
Restrequest4Delphi是一种使用任何编程语言编写的REST服务的API。
旨在以简单而简约的方式促进发展。
单击此处购买我们的正式培训!
../RESTRequest4Delphi/src
boss install github.com/viniciussanchez/RESTRequest4Delphi
默认情况下,使用Delphi时,使用TrestRequest , Trestresponse和Trestclient来提出请求。如果您使用Lazarus,则默认情况下使用FPHTTPClient组件。 RestRequest4Delphi对五个引擎提供了支持:RESTCLIENT, SYNAPSE , ICS OVERBYTE ,INDY和NETHTTP。您可以更改引擎以提出请求。为此,只需定义:项目>选项> Delphi编译器>有条件定义编译器指令RR4D_INDY , RR4D_SYNAPSE , RR4D_ICS或RR4D_NETHTTP
注意:对于Lazarus, FPHTTPCLIENT引擎是默认引擎。但是,您可以切换到Indy设置RR4D_INDY指令或突触设置RR4D_SYNAPSE指令。
适配器允许您在不更改项目核心的情况下扩展RestRequest4Delphi的功能。请参阅社区可用的适配器列表:
您需要使用RestRequest4D
uses RESTRequest4D; var
LResponse: IResponse;
begin
LResponse := TRequest.New.BaseURL( ' http://localhost:8888/users ' )
.AddHeader( ' HeaderName ' , ' HeaderValue ' )
.AddParam( ' ParameterName ' , ' ParameterValue ' )
.Accept( ' application/json ' )
.Get;
if LResponse.StatusCode = 200 then
ShowMessage(LResponse.Content);
end ; begin
TRequest.New.BaseURL( ' http://localhost:8888/users ' )
.Adapters(TDataSetSerializeAdapter.New(FDMemTable))
.Accept( ' application/json ' )
.Get;
end ; begin
TRequest.New.BaseURL( ' http://localhost:8888/users ' )
.ContentType( ' application/json ' )
.AddBody( ' {"name":"Vinicius","lastName":"Sanchez","email":"[email protected]"} ' )
.Post;
end ; begin
TRequest.New.BaseURL( ' http://localhost:8888/users/1 ' )
.ContentType( ' application/json ' )
.AddBody( ' {"name":"Vinicius","lastName":"Scandelai Sanchez","email":"[email protected]"} ' )
.Put;
end ; begin
TRequest.New.BaseURL( ' http://localhost:8888/users/1 ' )
.Accept( ' application/json ' )
.Delete;
end ;您可以在提出第一个请求之前使用BasicAuthentication , Token或TokenBearer方法设置凭据:
begin
Request.BasicAuthentication( ' username ' , ' password ' );
Request.Token( ' token-type ' + token);
Request.TokenBearer(token);
end ;您可以将其设置一次,并将其用于每个请求。
示例文件夹中开发了两个项目:
要运行该项目,您需要安装其依赖项(数据集 - 序列化)。要使用BOSS安装,请打开一个终端并输入:
boss install
如果您愿意,可以手动下载DataSet-Serialize并将其添加到Search Path中。
要运行服务器,您将需要node.js和npm 。安装了所有内容后,打开终端,安装依赖项并运行服务器:
npm install
node server.js
RESTRequest4Delphi是根据MIT许可证许可的免费和开源软件。