GithubHelp home page GithubHelp logo

jhonson's Introduction

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

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:

  • Delphi
  • Lazarus

⚡️ Quickstart 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<TJSONObject>;
      Res.Send<TJSONObject>(LBody);
    end);

  THorse.Listen(9000);
end;

⚡️ Quickstart Lazarus

{$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<TJSONObject>;
  Res.Send<TJSONObject>(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.

jhonson's People

Contributors

andre-djsystem avatar bragaped avatar dliocode avatar glerystonmatos avatar hunsche avatar snakeice avatar viniciussanchez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.