Skip to content

Repository files navigation

Object Pascal Delphi 2009+ Lazarus 4.x Windows: Delphi and FPC Linux: FPC only GitHub last commit Unit tests Doxygen Docs pages-build-deployment GitHub Repo stars

Daraja HTTP Framework

In short, Daraja enables Object Pascal developers to write well-structured HTTP server applications.

Contents

About

Daraja is a compact and flexible HTTP server application framework for Object Pascal, based on the HTTP server included in Indy - Internet Direct. The framework uses URL patterns to match requests to your resource handler code, and optional request filtering for pre- and post-processing. It enables developers to create well-structured HTTP server applications, written with 100% open source code.

Features

  • URL-pattern routing — map requests to handler classes by exact, prefix, suffix or default patterns
  • Web components — handle requests by overriding per-method hooks (OnGet, OnPost, OnPut, ...)
  • Filter chains — pluggable pre- and post-processing of requests and responses
  • Contexts — group resources under a base path with their own init parameters
  • HTTP sessions — server-side session state with configurable timeout
  • Static content — serve files from a directory with path-traversal protection (TdjDefaultWebComponent, see the note below)
  • Optional helpers — NCSA access logging and request-statistics filters
  • Dual compiler support — one codebase for Delphi 2009+ and Lazarus 4.x / FPC 3.2.x
  • AGPL or commercial — 100% open source, with a commercial license available

The static-content web component and the helper filters live in source/optional/, which is unsupported example code: review it before using it to serve untrusted content.

Usage

Prerequisites

The minimum requirements are:

Optional dependencies for some code examples and logging:

Get the source

Daraja and its dependencies are expected to sit side by side in the same parent directory:

Projects/
├── daraja-framework/      this repository
├── Indy/                  https://github.com/IndySockets/Indy  (10.6.2 or 10.6.3)
└── slf4p/                 https://github.com/michaelJustin/slf4p
mkdir Projects && cd Projects
git clone https://github.com/michaelJustin/daraja-framework.git
git clone https://github.com/IndySockets/Indy.git
git clone https://github.com/michaelJustin/slf4p.git

The demo and test project files use relative paths (..\..\..\Indy\..., ..\..\..\slf4p\src\main) that rely on this layout.

IDE configuration guide

To make Daraja HTTP Framework and Internet Direct (Indy) available for a project,

  • add the Daraja HTTP Framework <Install>/source folder to the project search path
  • add the folders <Indy>/Lib/Core, <Indy>/Lib/System and <Indy>/Lib/Protocols to the project search path

Example

These are the basic steps to configure a simple "Hello, World!" application. A simple resource will be defined in a TdjWebComponent which has only one method, OnGet. The web component will then be installed in the server.

Resource definition

A Daraja Web Component defines the request handling and response building, but it does not specify the actual location (HTTP address) of a resource. The web component in this example handles HTTP GET requests by overriding the OnGet method. The method sets the response content text and content type.

type
  THelloWorldResource = class(TdjWebComponent)
  public
    procedure OnGet(Request: TdjRequest; Response: TdjResponse); override;
  end;

procedure THelloWorldResource.OnGet(Request: TdjRequest; Response: TdjResponse);
begin
  Response.ContentText := 'Hello, World!';
  Response.ContentType := 'text/plain';
end;

Context and resource registration

We want to place the web component in the context tutorial and the absolute path /hello. We also want to use port 80. The full URL of our resource is http://127.0.0.1/tutorial/hello

procedure Demo;
var
  Server: TdjServer;
  Context: TdjWebAppContext;
begin
  Server := TdjServer.Create(80);
  try
    Context := TdjWebAppContext.Create('tutorial');
    Context.Add(THelloWorldResource, '/hello');
    Server.Add(Context);
    Server.Start;
    WriteLn('Server is running, please open http://127.0.0.1/tutorial/hello');
    WriteLn('Hit enter to terminate.');
    ReadLn;
  finally
    Server.Free;
  end;
end;

Full source: demo/01_helloworld/MainUnit.pas. More runnable examples — sessions, filters, static content, server-sent events, OpenID Connect — are in demo/.

Test with curl:

curl -i http://127.0.0.1/tutorial/hello
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: text/plain; charset=ISO-8859-1
Content-Length: 13
Date: Wed, 22 Jan 2025 19:07:14 GMT

Hello, World!

(The charset=ISO-8859-1 is appended automatically by Indy; the example code only sets text/plain.)

Documentation

API docs

API reference (Doxygen)

Getting started with Daraja

DarajaFrameworkGettingStarted.pdf (version 3.2.0, in this repository)

Changelog

See CHANGELOG.md for the release history.

Licensing

Daraja HTTP Framework is dual licensed under the GNU Affero General Public License and a commercial license. The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.

AGPL licensing FAQ

Can I use it in my commercial Project? Yes, if you open source your whole project (thus also AGPL it) otherwise no.
Is it enough to ship the licence texts or do I need to ship the source code (from Daraja) too? You have to supply the whole sourcecode of everything - but a download link should suffice.
Do I need to mention the use of Daraja inside my program (like a info message or something)? No, this is not required.

Commercial license

You can be released from the requirements of the AGPL license by purchasing a commercial license. The commercial license can be obtained from https://www.habarisoft.com/daraja_framework.html

Credits

This software uses the following open source packages:

For example code, unit testing, and documentation, it uses the following open source packages:

Origins

"Daraja" means "bridge" in Swahili. The Daraja Framework serves as a bridge between incoming HTTP requests and the Object Pascal code that handles them, enabling seamless integration between web traffic and application logic. — ChatGPT, OpenAI (May 2025)

"Daraja" is Swahili for "bridge" — a fitting name, since the framework is the bridge between an incoming HTTP request and the Object Pascal code that answers it: it matches each request by URL pattern and passes it to your handler class. — Claude Sonnet 5, Anthropic (September 2026)

About

A compact and flexible HTTP server application framework for Object Pascal based on Internet Direct (Indy)

Topics

Resources

Stars

160 stars

Watchers

25 watching

Forks

Releases

Used by

Contributors

Languages