delphi ipub-refit
delphi ipub-refit
unit Unit2;
//https://github.com/viniciusfbb/ipub-refit
interface
uses
REST.Authenticator.OAuth,
ipub.Rtl.Refit, Winapi.Windows, Winapi.Messages, System.SysUtils,
System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, Vcl.StdCtrls;
type
TUser = record
name: string;
location: string;
id: Integer;
end;
[BaseUrl('https://api.github.com')]
IUser = interface(IipRestApi)
['{36AF7C59-E4D2-4EB6-8F6F-8380E88FE7D5}']
[Headers('Header-A', '1')]
[Post('/users/{aUser}')]
function GetUsers(const AUser: string): tarray<TUser>;
[Post('/users/{aUser}')]
function GetUsersJson(const AUser: string): string;
function GetApiKey: string;
procedure SetApiKey(const AValue: string);
property ApiKey: string read GetApiKey write SetApiKey;
end;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
var Api: IUser;
var Users: tarray<TUser>;
var auth: TOAuth2Authenticator;
auth := TOAuth2Authenticator.Create(nil);
Api := GRestService.&For<IUser>;
Api.ApiKey := 'XXXXX';
api.Authenticator := auth;
Users := api.GetUsers('user1');
Showmessage(api.GetUsersJson('user1'));
auth.Free;
end;
end.
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/16321128.html

浙公网安备 33010602011771号