2016-05-23 17:26:00 +02:00
|
|
|
unit MainClientFormU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
|
|
|
|
System.Classes, Vcl.Graphics,
|
2016-06-23 11:42:16 +02:00
|
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
|
2016-05-23 17:26:00 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
TForm5 = class(TForm)
|
2016-06-23 11:42:16 +02:00
|
|
|
Memo1: TMemo;
|
|
|
|
Memo2: TMemo;
|
|
|
|
Panel1: TPanel;
|
2016-05-23 17:26:00 +02:00
|
|
|
btnGet: TButton;
|
|
|
|
btnLOGIN: TButton;
|
2016-06-23 11:42:16 +02:00
|
|
|
Splitter1: TSplitter;
|
2016-05-23 17:26:00 +02:00
|
|
|
procedure btnGetClick(Sender: TObject);
|
|
|
|
procedure btnLOGINClick(Sender: TObject);
|
|
|
|
private
|
2016-06-23 11:42:16 +02:00
|
|
|
FJWT: String;
|
|
|
|
procedure SetJWT(const Value: String);
|
|
|
|
property JWT: String read FJWT write SetJWT;
|
2016-05-23 17:26:00 +02:00
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
Form5: TForm5;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
2016-06-23 12:11:01 +02:00
|
|
|
MVCFramework.RESTClient, ObjectsMappers;
|
2016-05-23 17:26:00 +02:00
|
|
|
|
|
|
|
procedure TForm5.btnGetClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
lClient: TRESTClient;
|
2016-06-23 12:11:01 +02:00
|
|
|
lResp: IRESTResponse;
|
2016-06-23 11:42:16 +02:00
|
|
|
lQueryStringParams: TStringList;
|
2016-05-23 17:26:00 +02:00
|
|
|
begin
|
|
|
|
lClient := TRESTClient.Create('localhost', 8080);
|
|
|
|
try
|
2016-06-23 11:42:16 +02:00
|
|
|
lClient.ReadTimeOut(0);
|
|
|
|
if not FJWT.IsEmpty then
|
|
|
|
lClient.RequestHeaders.Values['Authentication'] := 'bearer ' + FJWT;
|
|
|
|
lQueryStringParams := TStringList.Create;
|
|
|
|
try
|
|
|
|
lQueryStringParams.Values['firstname'] := 'Daniele';
|
|
|
|
lQueryStringParams.Values['lastname'] := 'Teti';
|
2016-06-23 12:11:01 +02:00
|
|
|
lResp := lClient.doGET('/admin/role1', [], lQueryStringParams);
|
|
|
|
|
|
|
|
if lResp.HasError then
|
|
|
|
ShowMessage(lResp.Error.ExceptionMessage);
|
|
|
|
|
2016-06-23 11:42:16 +02:00
|
|
|
finally
|
|
|
|
lQueryStringParams.Free;
|
|
|
|
end;
|
2016-06-23 12:11:01 +02:00
|
|
|
Memo2.Lines.Text := lResp.BodyAsString;
|
2016-05-23 17:26:00 +02:00
|
|
|
finally
|
|
|
|
lClient.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm5.btnLOGINClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
lClient: TRESTClient;
|
|
|
|
lRest: IRESTResponse;
|
|
|
|
begin
|
|
|
|
lClient := TRESTClient.Create('localhost', 8080);
|
|
|
|
try
|
2016-06-23 11:42:16 +02:00
|
|
|
lClient.ReadTimeOut(0);
|
2016-05-23 17:26:00 +02:00
|
|
|
lClient
|
2016-06-23 11:42:16 +02:00
|
|
|
.Header('jwtusername', 'user1')
|
|
|
|
.Header('jwtpassword', 'user1');
|
2016-05-23 17:26:00 +02:00
|
|
|
lRest := lClient.doPOST('/login', []);
|
2016-06-23 11:42:16 +02:00
|
|
|
JWT := lRest.BodyAsJSONObject.GetValue('token').Value;
|
2016-05-23 17:26:00 +02:00
|
|
|
finally
|
|
|
|
lClient.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-23 11:42:16 +02:00
|
|
|
procedure TForm5.SetJWT(const Value: String);
|
|
|
|
begin
|
|
|
|
FJWT := Value;
|
|
|
|
Memo1.Lines.Text := Value;
|
|
|
|
end;
|
|
|
|
|
2016-05-23 17:26:00 +02:00
|
|
|
end.
|