Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hashload/horse-octet-stream
octet-stream middleware for horse
https://github.com/hashload/horse-octet-stream
horse horse-octet-stream middleware pdf stream
Last synced: 21 days ago
JSON representation
octet-stream middleware for horse
- Host: GitHub
- URL: https://github.com/hashload/horse-octet-stream
- Owner: HashLoad
- License: mit
- Created: 2018-10-19T16:56:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-22T00:26:54.000Z (10 months ago)
- Last Synced: 2024-04-14T00:25:41.372Z (10 months ago)
- Topics: horse, horse-octet-stream, middleware, pdf, stream
- Language: Pascal
- Size: 693 KB
- Stars: 69
- Watchers: 13
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# horse-octet-stream
horse-octet-stream is an official middleware for working with Stream 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 horse-octet-stream
```
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*
```
../horse-octet-stream/src
```## ✔️ Compatibility
This middleware is compatible with projects developed in:
- [X] Delphi
- [X] Lazarus## ⚡️ Quickstart Delphi
```delphi
uses
Horse,
Horse.OctetStream, // It's necessary to use the unit
System.Classes,
System.SysUtils;begin
// It's necessary to add the middleware in the Horse:
THorse.Use(OctetStream);THorse.Get('/stream',
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
var
LStream: TFileStream;
begin
// Now you can send your stream:
LStream := TFileStream.Create(ExtractFilePath(ParamStr(0)) + 'horse.pdf', fmOpenRead);
Res.Send(LStream);
end);THorse.Listen(9000);
end;
```## ⚡️ Quickstart Lazarus
```delphi
{$MODE DELPHI}{$H+}uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Horse,
Horse.OctetStream, // It's necessary to use the unit
SysUtils,
Classes;procedure GetStream(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
var
LStream: TFileStream;
begin
// Now you can send your stream:
LStream := TFileStream.Create(ExtractFilePath(ParamStr(0)) + 'horse.pdf', fmOpenRead);
Res.Send(LStream).ContentType('application/pdf');
end;begin
// It's necessary to add the middleware in the Horse:
THorse.Use(OctetStream);THorse.Get('/stream', GetStream);
THorse.Listen(9000);
end.
```## ⚠️ License
`horse-octet-stream` is free and open-source middleware licensed under the [MIT License](https://github.com/HashLoad/horse-octet-stream/blob/master/LICENSE).