Building Servers
43.1 Options Overview
Classic web framework (ISAPI, Apache module, standalone/console, CGI)
Bundled, low-level, TWebModule with actions RAD Server (Enterprise) REST application server (EMS)
Resource modules with attributes, user/group management, analytics, FireDAC JSON Multi-tier (legacy) Server methods, REST/TCP, callbacks
Express.js-like micro-framework (open source) Very popular. Middleware: JWT, CORS, JSON.
Full SOA/ORM/REST framework (open source) Extremely fast, Delphi and FPC, Linux servers DMVCFramework (DelphiMVCFramework) MVC/REST framework (open source)
Mature, active, Swagger, JWT, ActiveRecord Indy TIdHTTPServer Low-level HTTP server TMS XData / Sparkle Commercial REST/ORM OpenAPI, Aurelius integration
43.2 Horse Example
program HorseApi;
{$APPTYPE CONSOLE}
uses
Horse, Horse.Jhonson, System.JSON; // install with Boss: boss install horse horse-jhonson
begin
THorse.Use(Jhonson); // JSON middleware
THorse.Get('/ping',
procedure(Req: THorseRequest; Res: THorseResponse)
begin
Res.Send('pong');
end);
THorse.Get('/customers/:id',
procedure(Req: THorseRequest; Res: THorseResponse)
begin
var Obj := TJSONObject.Create;
Obj.AddPair('id', Req.Params['id']);
Obj.AddPair('name', 'Ana');
Res.Send<TJSONObject>(Obj);
end);
THorse.Post('/customers',
procedure(Req: THorseRequest; Res: THorseResponse)
begin
var Body := Req.Body<TJSONObject>;
Res.Send(Body.ToJSON).Status(THTTPStatus.Created);
end);
THorse.Listen(9000);
end.43.3 WebBroker Basics
Deployment: Windows service, IIS (ISAPI), Apache module (Linux/Windows), or standalone console/daemon behind nginx/IIS reverse proxies. Linux servers need the Enterprise edition.
Security: HTTPS (reverse proxy or TLS in Indy with OpenSSL), JWT auth (delphi-jose-jwt), input validation, parameterized SQL, CORS, rate limiting.
procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
Response.ContentType := 'application/json';
Response.Content := '{"status":"ok"}';
end;