Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/viniciussanchez/restrequest4delphi
API to consume REST services written in any programming language with support to Lazarus and Delphi
https://github.com/viniciussanchez/restrequest4delphi
api client delphi embarcadero fpc freepascal indy lazarus nethttp request rest simple
Last synced: 6 days ago
JSON representation
API to consume REST services written in any programming language with support to Lazarus and Delphi
- Host: GitHub
- URL: https://github.com/viniciussanchez/restrequest4delphi
- Owner: viniciussanchez
- License: mit
- Created: 2019-07-03T20:02:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T10:53:53.000Z (19 days ago)
- Last Synced: 2024-12-06T11:32:41.565Z (19 days ago)
- Topics: api, client, delphi, embarcadero, fpc, freepascal, indy, lazarus, nethttp, request, rest, simple
- Language: Pascal
- Homepage: https://go.hotmart.com/U88695509H
- Size: 2.26 MB
- Stars: 544
- Watchers: 45
- Forks: 158
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
RESTRequest4Delphi is a API to consume REST services written in any programming language.
Designed to facilitate development, in a simple and minimalist way.
Buy our official training by clicking here!
## ⚙️ Installation* **Manual installation**: Add the following folders to your project, in *Project > Options > Building > Delphi Compiler > Search path*
```
../RESTRequest4Delphi/src
```* Installation using the [**Boss**](https://github.com/HashLoad/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 [**fphttpclient**](https://wiki.lazarus.freepascal.org/fphttpclient) components are used by default. The RESTRequest4Delphi has support to five engines to make requests: RESTClient, [**Synapse**](http://www.ararat.cz/synapse/doku.php/download), [**ICS Overbyte**](https://wiki.overbyte.eu/wiki/index.php/ICS_Download), 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**](http://www.ararat.cz/synapse/doku.php/download) 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:
* [**dataset-serialize-adapter-restrequest4delphi**](https://github.com/viniciussanchez/dataset-serialize-adapter-restrequest4delphi) - Adapter to load a DataSet using the DataSet-Serialize library at the time of the request;
* [**csv-adapter-restrequest4delphi**](https://github.com/Code4Delphi/csv-adapter-restrequest4delphi) - Allows you to generate a text or CSV file with the content of a request;## ⚡️ Quickstart
You need to use RESTRequest4D
```pascal
uses RESTRequest4D;
```* **GET**
```pascal
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 USING ADAPTERS**
```pascal
begin
TRequest.New.BaseURL('http://localhost:8888/users')
.Adapters(TDataSetSerializeAdapter.New(FDMemTable))
.Accept('application/json')
.Get;
end;
```* **POST**
```pascal
begin
TRequest.New.BaseURL('http://localhost:8888/users')
.ContentType('application/json')
.AddBody('{"name":"Vinicius","lastName":"Sanchez","email":"[email protected]"}')
.Post;
end;
```* **PUT**
```pascal
begin
TRequest.New.BaseURL('http://localhost:8888/users/1')
.ContentType('application/json')
.AddBody('{"name":"Vinicius","lastName":"Scandelai Sanchez","email":"[email protected]"}')
.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`, `Token` or `TokenBearer` method before making the first request:
```pascal
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:
* **client**: Windows VCL application consuming a REST API developed in Node.js
To run the project, you need to install its dependencies ([**DataSet-Serialize**](https://github.com/viniciussanchez/dataset-serialize)). To install using [**Boss**](https://github.com/HashLoad/boss), open a terminal and type:
```
boss install
```
If you prefer, you can manually download the `DataSet-Serialize` and add it to `Search Path`.* **server-node**: REST server developed with [**Node.js**](https://nodejs.org/en/) and [**Express**](https://expressjs.com/).
To run the server you will need [**Node.js**](https://nodejs.org/en/) and [**NPM**](https://www.npmjs.com/). With everything installed, open a terminal, install the dependencies and run the server:
```
npm install
node server.js
```## 💻 Code Contributors
## ⚠️ License
`RESTRequest4Delphi` is free and open-source software licensed under the [MIT License](https://github.com/viniciussanchez/RESTRequest4Delphi/blob/master/LICENSE).