Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HashLoad/jhonson
Middleware for parse JSON in HORSE
https://github.com/HashLoad/jhonson
horse json middleware parser
Last synced: 3 months ago
JSON representation
Middleware for parse JSON in HORSE
- Host: GitHub
- URL: https://github.com/HashLoad/jhonson
- Owner: HashLoad
- License: mit
- Created: 2018-10-02T19:43:57.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-28T12:38:54.000Z (11 months ago)
- Last Synced: 2024-04-13T21:53:47.164Z (7 months ago)
- Topics: horse, json, middleware, parser
- Language: Pascal
- Size: 41 KB
- Stars: 94
- Watchers: 13
- Forks: 23
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jhonson
Jhonson is a official middleware for working with JSON in APIs developed with the Horse framework.
We created a channel on Telegram for questions and support:
## ⚙️ Installation
Installation is done using the [`boss install`](https://github.com/HashLoad/boss) command:
``` sh
boss install jhonson
```
If you choose to install manually, simply add the following folders to your project, in *Project > Options > Resource Compiler > Directories and Conditionals > Include file search path*
```
../jhonson/src
```## ✔️ Compatibility
This middleware is compatible with projects developed in:
- [X] Delphi
- [X] Lazarus## ⚡️ Quickstart Delphi
```delphi
uses
Horse,
Horse.Jhonson, // It's necessary to use the unit
System.JSON;begin
// It's necessary to add the middleware in the Horse:
THorse.Use(Jhonson());
// You can specify the charset when adding middleware to the Horse:
// THorse.Use(Jhonson('UTF-8'));THorse.Post('/ping',
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
var
LBody: TJSONObject;
begin
// Req.Body gives access to the content of the request in string format.
// Using jhonson middleware, we can get the content of the request in JSON format.
LBody := Req.Body;
Res.Send(LBody);
end);THorse.Listen(9000);
end;
```## ⚡️ Quickstart Lazarus
```delphi
{$MODE DELPHI}{$H+}uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Horse,
Horse.Jhonson, // It's necessary to use the unit
fpjson,
SysUtils;procedure PostPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
var
LBody: TJSONObject;
begin
// Req.Body gives access to the content of the request in string format.
// Using jhonson middleware, we can get the content of the request in JSON format.
LBody := Req.Body;
Res.Send(LBody);
end;begin
// It's necessary to add the middleware in the Horse:
THorse.Use(Jhonson);
// You can specify the charset when adding middleware to the Horse:
// THorse.Use(Jhonson('UTF-8'));THorse.Post('/ping', PostPing);
THorse.Listen(9000);
end.
```## ⚠️ License
`Jhonson` is free and open-source middleware licensed under the [MIT License](https://github.com/HashLoad/jhonson/blob/master/LICENSE).