Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

RESTRequest4Delphi

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

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
pascal
../RESTRequest4Delphi/src/core
../RESTRequest4Delphi/src/interfaces
  • Installation using the Boss:
pascal
boss install github.com/viniciussanchez/RESTRequest4Delphi

⚡️ Quickstart

You need to use RESTRequest4D.Request

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

pascal
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:

pascal
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:

pascal
npm install
node server.js

⚠️ License

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