-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWiRLDemo01.dpr
More file actions
70 lines (51 loc) · 1.23 KB
/
WiRLDemo01.dpr
File metadata and controls
70 lines (51 loc) · 1.23 KB
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
program WiRLDemo01;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
WiRL.http.Server,
WiRL.http.Server.Indy,
WiRL.Core.Engine,
WiRL.Core.Registry,
WiRL.Core.Attributes,
WiRL.http.Accept.MediaType,
WiRL.Core.MessageBody.Default;
type
TPerson = class(TObject)
private
FName: string;
public
property Name: string read FName write FName;
end;
[Path('person')]
TPersonResource = class
public
[GET]
[Produces(TMediaType.APPLICATION_JSON)]
function GetPerson([QueryParam('name')] const AName: string): TPerson;
end;
var
LServer: TWiRLServer;
{ TPersonResource }
function TPersonResource.GetPerson(const AName: string): TPerson;
begin
Result := TPerson.Create;
Result.Name := AName;
end;
begin
// Resources should be registered before activate the server
// In a more complex app you can do the registration in the
// initialization section of the unit of the class
TWiRLResourceRegistry.Instance.RegisterResource<TPersonResource>;
LServer := TWiRLServer.Create(nil);
try
LServer.SetPort(8080);
LServer.AddEngine<TWiRLEngine>('rest')
.AddApplication('app')
.SetResources('*');
LServer.Active := True;
Readln;
finally
LServer.Free;
end;
end.