Skip to content

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

License

Notifications You must be signed in to change notification settings

michaelJustin/daraja-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AGPL License GitHub top language Static Badge GitHub Release GitHub Release Date - Published_At GitHub last commit Doxygen Docs pages-build-deployment GitHub Repo stars

⭐ Star us on GitHub — it motivates us a lot!

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

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.

Usage

Prerequisites

The minimum requirements are:

Optional requirements for some code examples and logging:

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

A simple "Hello, World!" application.

Resource definition

A Daraja Web Component defines the request handling and response building, but it does not specifiy 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.

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

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

Tested with curl:

curl -i http://127.0.0.1/demo/hello.txt
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!
Flowchart diagram
flowchart TD
    A[TdjServer] -->|Receive request| B(Locate TdjWebcomponent)
    B --> C{Invoke HTTP method}
    C -->|**GET**| D[**run OnGet**]
    C -->|POST| E[run OnPost]
    C -->|PUT| F[run OnPut]

    

Loading

Documentation

API docs

https://michaeljustin.github.io/daraja-framework/

Getting started with Daraja

https://www.habarisoft.com/daraja_framework/3.0.3/docs/DarajaFrameworkGettingStarted.pdf

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.

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:

  • JsonDataObjects for example code
  • Log4D for logging
  • DUnit and FPCUnit for unit testing
  • Doxygen Doxygen is a widely-used documentation generator tool in software development
  • pas2dox Pas2dox is a pre-processor addon for the Doxygen documentation generator.

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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages