Horse Octet Stream Save

octet-stream middleware for horse

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

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:

  • Delphi
  • Lazarus

⚡️ Quickstart 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<TStream>(LStream);
    end);

  THorse.Listen(9000);
end;

⚡️ Quickstart Lazarus

{$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<TStream>(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.

Open Source Agenda is not affiliated with "Horse Octet Stream" Project. README Source: HashLoad/horse-octet-stream
Stars
69
Open Issues
1
Last Commit
1 week ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating