下面是使用 Delphi 调用 API 的示例函数:
uses
REST.Client, REST.Types, REST.Authenticator.Basic, REST.Authenticator.OAuth;
procedure TForm1.Button1Click(Sender: TObject);
var
RESTClient: TRESTClient;
RESTRequest: TRESTRequest;
RESTResponse: TRESTResponse;
begin
RESTClient := TRESTClient.Create('http://example.com/api');
try
RESTRequest := TRESTRequest.Create(RESTClient);
try
RESTResponse := TRESTResponse.Create(RESTClient);
try
RESTRequest.Resource := '/users';
RESTRequest.Method := TRESTRequestMethod.rmGET;
RESTRequest.Execute;
ShowMessage(RESTResponse.Content);
finally
RESTResponse.Free;
end;
finally
RESTRequest.Free;
end;
finally
RESTClient.Free;
end;
end;