forked from pedrolopix/DelphiSimpleRestServer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit1.pas
82 lines (65 loc) · 1.77 KB
/
Unit1.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent,
IdCustomTCPServer, IdCustomHTTPServer, IdHTTPServer, IdContext, HttpServerCommand;
type
TForm1 = class(TForm)
IdHTTPServer1: TIdHTTPServer;
procedure IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
procedure FormCreate(Sender: TObject);
private
FCommand: THttpServerCommand;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TRestTeste=class(TRESTCommand)
protected
procedure execute; override;
end;
TRestTeste2=class(TRESTCommand)
protected
procedure execute; override;
end;
TRestTesteParam=class(TRESTCommand)
protected
procedure execute; override;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FCommand:= THttpServerCommand.Create(self);
FCommand.Commands.Register('GET','/teste1', TRestTeste);
FCommand.Commands.Register('GET','/teste2', TRestTeste2);
FCommand.Commands.Register('GET','/teste3/:param1', TRestTesteParam);
end;
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
FCommand.CommandGet(AContext, ARequestInfo, AResponseInfo);
end;
{ TRestTeste }
procedure TRestTeste.execute;
begin
inherited;
ResponseJSON('{''teste'':''ok''}');
end;
{ TRestTeste2 }
procedure TRestTeste2.execute;
begin
inherited;
ResponseJSON('{''teste2'':''ok''}');
end;
{ TRestTesteParam }
procedure TRestTesteParam.execute;
begin
inherited;
ResponseJSON('{''params'':'+QuotedStr(params.commatext)+'}');
end;
end.