Home

Awesome

<p align="center"> <a href="https://github.com/viniciussanchez/RESTRequest4Delphi/blob/master/img/logo.png"> <img alt="Horse" height="150" src="https://github.com/viniciussanchez/RESTRequest4Delphi/blob/master/img/logo.png"> </a> </p><br> <p align="center"> <b>RESTRequest4Delphi</b> is a API to consume <a href="https://en.wikipedia.org/wiki/Representational_state_transfer"><b>REST</b></a> services written in <b>any</b> programming language.<br>Designed to facilitate development, in a <b>simple</b> and <b>minimalist</b> way. <br>Buy our official training by <a href="https://go.hotmart.com/U88695509H"><b>clicking here</b></a>! </p><br> <p align="center"> <img src="https://img.shields.io/github/v/release/viniciussanchez/RESTRequest4Delphi?style=flat-square"> <img src="https://img.shields.io/github/stars/viniciussanchez/RESTRequest4Delphi?style=flat-square"> </p>

⚙️ Installation

../RESTRequest4Delphi/src
boss install github.com/viniciussanchez/RESTRequest4Delphi

🔰 Engines

By default, the components TRESTRequest, TRESTResponse and TRESTClient are used to make requests when your using Delphi. If you use Lazarus, the fphttpclient components are used by default. The RESTRequest4Delphi has support to five engines to make requests: RESTClient, Synapse, ICS Overbyte, Indy and NetHTTP. You can change the engine to make requests. To do this, simply define in: Project > Options > Delphi Compiler > Conditional defines the compiler directive RR4D_INDY, RR4D_SYNAPSE, RR4D_ICS or RR4D_NETHTTP

Note: for Lazarus, the fphttpclient engine is the default. But you can switch to Indy setting RR4D_INDY directive or to Synapse setting RR4D_SYNAPSE directive.

🔌 Adapters

Adapters allow you to extend the functionality of RESTREquest4Delphi without changing the core of the project. See the list of adapters available by the community:

⚡️ Quickstart

You need to use 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":"viniciuss.sanchez@gmail.com"}')
    .Post;
end;
begin
  TRequest.New.BaseURL('http://localhost:8888/users/1')
    .ContentType('application/json')
    .AddBody('{"name":"Vinicius","lastName":"Scandelai Sanchez","email":"viniciuss.sanchez@gmail.com"}')
    .Put;
end;
begin
  TRequest.New.BaseURL('http://localhost:8888/users/1')
    .Accept('application/json')
    .Delete;
end;

🔒 Authentication

You can set credentials using the BasicAuthentication, Token or TokenBearer method before making the first request:

begin
  Request.BasicAuthentication('username', 'password');
  Request.Token('token-type ' + token);
  Request.TokenBearer(token);
end;

You can set it once and it will be used for every request.

📝 Samples

Two projects were developed within the examples folder:

To run the project, you need to install its dependencies (DataSet-Serialize). To install using Boss, open a terminal and type:

boss install

If you prefer, you can manually download the DataSet-Serialize and add it to Search Path.

To run the server you will need Node.js and NPM. With everything installed, open a terminal, install the dependencies and run the server:

npm install
node server.js

💻 Code Contributors

<img src="https://opencollective.com/restrequest4delphi/contributors.svg?width=890&button=false" alt="Code Contributors" style="max-width:100%;">

⚠️ License

RESTRequest4Delphi is free and open-source software licensed under the MIT License.