Skip to content
/ MARS Public
forked from andrea-magni/MARS

MARS-Curiosity Delphi REST Library

License

Notifications You must be signed in to change notification settings

meg02in/MARS

 
 

Repository files navigation

MARS-curiosity logo

Delphi REST Library

  1. Lightweight
  2. Easy and powerful
  3. 100% RESTful Web Service
  4. Delphi-like
  5. Advanced dataset support with FireDAC

More features ...

Installation

  1. Clone or download this project
  2. Add folders to RAD Studio Library Path
  3. Build All in the RAD Studio IDE
  4. Install two packages

More about the installation ...

Use the Code Luke!

Build REST server with MARS Curiosity is very easy. To run a simple REST server just create a new Console Application and use the following code:

program Mars1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  MARS.Core.Engine,
  MARS.http.Server.Indy,
  MARS.mORMotJWT.Token,
  MARS.Core.MessageBodyWriters,
  MARS.Core.Attributes,
  MARS.Core.MediaType,
  MARS.Core.Registry;

type
  [Path('helloworld')]
  THelloWorldResource = class
  public
    [GET, Produces(TMediaType.TEXT_PLAIN)]
    function SayHelloWorld: string;
  end;

function THelloWorldResource.SayHelloWorld: string;
begin
  Result := 'Hello World! Here is MARS Curiosity ...';
end;

var
  FEngine: MARS.Core.Engine.TMARSEngine;
  FServer: MARS.http.Server.Indy.TMARShttpServerIndy;
begin
  // ----------------------------------
  // Register a resource class
  MARS.Core.Registry.TMARSResourceRegistry.Instance.
    RegisterResource<THelloWorldResource>;
  // ----------------------------------
  // Build and configure the engine
  FEngine := MARS.Core.Engine.TMARSEngine.Create;
  FEngine.BasePath := '/rest';
  FEngine.Port := 8080;
  FEngine.AddApplication('DefaultAPI', '/default', ['*.THelloWorldResource']);
  FServer := MARS.http.Server.Indy.TMARShttpServerIndy.Create(FEngine);
  // ----------------------------------
  // Run the REST server
  FServer.Active := True;
  Writeln ('Server is running ...');
  Write ('Press Enter to stop ...');
  Readln;
  // ----------------------------------
  // Close the server
  FServer.Active := False;
  FreeAndNil(FServer);
  FreeAndNil(FEngine);
end.

Documentation

Forum

Official MARS Curiosity forum at Delphi-Praxis International: https://en.delphipraxis.net/forum/34-mars-curiosity-rest-library/

Contribution

It would be great if you would like to support this project. It's quite easy and you can became better Gitter then.

Thanks

Most of the code has been written by the author (Andrea Magni) with some significant contributions by Nando Dessena, Stefan Glienke and Davide Rossi. Some of my customers actually act as beta testers and early adopters. I want to thank them all for the trust and effort.

COPYRIGHTS

  • The Delphi stylized helmet icon is trademark of Embarcadero Technologies.

About

MARS-Curiosity Delphi REST Library

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Pascal 98.2%
  • Other 1.8%