
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許可證許可的免費和開源軟件。