88 System.SysUtils,
99 System.JSON,
1010 Horse,
11- Horse.Jhonson,
12- Horse.HandleException;
11+ Horse.Jhonson;
1312
1413const
1514 PORT = 9050 ;
@@ -24,36 +23,36 @@ begin
2423 Res.Send(' pong' );
2524 end );
2625
27- THorse.Get(' /clientes ' ,
26+ THorse.Get(' /clients ' ,
2827 procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
2928 var
30- LJSONObjectRetorno : TJSONObject;
31- LJSONObjectCliente : TJSONObject;
29+ LJSONObjectResult : TJSONObject;
30+ LJSONObjectClient : TJSONObject;
3231 LJSONArray: TJSONArray;
33- LNumRegistrosGerar : Integer;
32+ LNumberRecords : Integer;
3433 i: Integer;
3534 begin
36- LNumRegistrosGerar := 10 ;
37- if Req.Query.ContainsKey(' numero-registros-gerar ' ) then
38- LNumRegistrosGerar := Req.Query.Field(' numero-registros-gerar ' ).AsInteger;
35+ LNumberRecords := 10 ;
36+ if Req.Query.ContainsKey(' number-records ' ) then
37+ LNumberRecords := Req.Query.Field(' number-records ' ).AsInteger;
3938
4039 LJSONArray := TJSONArray.Create;
41- for i := 1 to LNumRegistrosGerar do
40+ for i := 1 to LNumberRecords do
4241 begin
43- LJSONObjectCliente := TJSONObject.Create;
44- LJSONObjectCliente .AddPair(' id' , TJSONNumber.Create(i));
45- LJSONObjectCliente .AddPair(' nome ' , ' Nome cliente ' + i.ToString);
46- LJSONObjectCliente .AddPair(' email' ,' nome ' + i.ToString + ' @code4delphi.com.br' );
47- LJSONArray.AddElement(LJSONObjectCliente );
42+ LJSONObjectClient := TJSONObject.Create;
43+ LJSONObjectClient .AddPair(' id' , TJSONNumber.Create(i));
44+ LJSONObjectClient .AddPair(' name ' , ' Name Client ' + i.ToString);
45+ LJSONObjectClient .AddPair(' email' , ' name ' + i.ToString + ' @code4delphi.com.br' );
46+ LJSONArray.AddElement(LJSONObjectClient );
4847 end ;
4948
50- LJSONObjectRetorno := TJSONObject.Create;
51- LJSONObjectRetorno .AddPair(' data' , LJSONArray);
52- LJSONObjectRetorno .AddPair(' records' , TJSONNumber.Create(LNumRegistrosGerar ));
53- Res.Send<TJSONObject>(LJSONObjectRetorno );
49+ LJSONObjectResult := TJSONObject.Create;
50+ LJSONObjectResult .AddPair(' data' , LJSONArray);
51+ LJSONObjectResult .AddPair(' records' , TJSONNumber.Create(LNumberRecords ));
52+ Res.Send<TJSONObject>(LJSONObjectResult );
5453 end );
5554
56- THorse.Get(' /clientes /:id' ,
55+ THorse.Get(' /clients /:id' ,
5756 procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
5857 var
5958 LJSONObject: TJSONObject;
@@ -63,14 +62,14 @@ begin
6362
6463 LJSONObject := TJSONObject.Create;
6564 LJSONObject.AddPair(' id' , TJSONNumber.Create(LId.ToInteger));
66- LJSONObject.AddPair(' nome ' , ' Nome cliente ' + LId);
67- LJSONObject.AddPair(' email' ,' nome ' + LId + ' @code4delphi.com.br' );
65+ LJSONObject.AddPair(' name ' , ' Name Client ' + LId);
66+ LJSONObject.AddPair(' email' , ' name ' + LId + ' @code4delphi.com.br' );
6867 Res.Send<TJSONObject>(LJSONObject);
6968 end );
7069
7170 THorse.Listen(PORT,
7271 procedure
7372 begin
74- Writeln(' Porta atual: ' + PORT.ToString);
73+ Writeln(' CSV Adapter For RESTRequest4D is running on the port ' + PORT.ToString);
7574 end );
7675end .
0 commit comments