Need help with RESTRequest4Delphi?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

viniciussanchez
156 Stars 49 Forks MIT License 178 Commits 3 Opened issues

Description

API to consume REST services written in any programming language with support to Lazarus and Delphi

Services available

!
?

Need anything else?

Contributors list

# 138,734
Node.js
C
delphi
fpc
103 commits

Horse


RESTRequest4Delphi is a API to consume REST services written in any programming language.
Designed to facilitate development, in a simple and minimalist way.


⚙️ Installation

Prerequisites: DataSet-Serialize - This is a DataSet serializer for Delphi

  • Manual installation: Add the following folders to your project, in Project > Options > Resource Compiler > Directories and Conditionals > Include file search path
../RESTRequest4Delphi/src
  • Installation using the Boss:
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 Indy components are used by default. The RESTRequest4Delphi has support to three enginies to make requests: RESTClient, 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
or
RR4D_NETHTTP

**Note: for Lazarus, only the engine using Indy is available and it is already the default. You don't need to define directive.

⚡️ Quickstart

You need to use RESTRequest4D

uses RESTRequest4D;
  • GET
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;
  • GET AS DATASET
begin
  TRequest.New.BaseURL('http://localhost:8888/users')
    .Accept('application/json')
    .DataSetAdapter(FDMemTable)
    .Get;
end;
  • POST
begin
  TRequest.New.BaseURL('http://localhost:8888/users')
    .Accept('application/json')
    .AddBody('{"name":"Vinicius","lastName":"Sanchez","email":"[email protected]"}')
    .Post;
end;
  • PUT
begin
  TRequest.New.BaseURL('http://localhost:8888/users/1')
    .Accept('application/json')
    .AddBody('{"name":"Vinicius","lastName":"Scandelai Sanchez","email":"[email protected]"}')
    .Put;
end;
  • DELETE
begin
  TRequest.New.BaseURL('http://localhost:8888/users/1')
    .Accept('application/json')
    .Delete;
end;

🔒 Authentication

You can set credentials using the

BasicAuthentication
or
Token
method before making the first request:
begin
  Request.BasicAuthentication('username', 'password');
  Request.Token('bearer token');
end;

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

📝 Samples

Two projects were developed within the examples folder:

  • client: Windows VCL application consuming a REST API developed in Node.js

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

⚠️ License

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.