Jump to content
Sign in to follow this  
mjustin

Daraja HTTP Server Framework 2.5 preview snapshot

Recommended Posts

The Daraja HTTP Server Framework is a free open source library for Object Pascal (Free Pascal 3,1.0 or Delphi 2009+), based on the stand-alone HTTP server component in Internet Direct (Indy).

 

With the 2.5-SNAPSHOT release, most code is now single-source and more readable, there are no "IFDEF FPC" branches anymore to use the Free Pascal fgl generics library.

All DUnit / FPCUnit - based tests run successfully. The full 2.5-SNAPSHOT source and demo code is available at GitHub.

Demo applications cover - for example - OAuth 2.0 and Twitter Bootstrap.


More information
- GitHub: https://github.com/michaelJustin/daraja-framework
- API documentation: http://michaeljustin.github.io/daraja-framework/
- Wiki: https://github.com/michaelJustin/daraja-framework/wiki
- Features and FAQ: https://www.habarisoft.com/daraja_framework.html


image.thumb.png.4786da403a515e67e8382b86e748eb28.png

  • Like 2

Share this post


Link to post

The Daraja HTTP Server Framework is a free open source library for Object Pascal (Free Pascal 3.2.0 or Delphi 2009+), based on the HTTP server component in Internet Direct (Indy).

New: the 2.6-SNAPSHOT includes a first implementation of the Web Filter API, which allows pre- and postprocessing of HTTP requests and responses.
Web Filters are useful for example to add logging and auditing, input validation, or authentication.
Filters may be composed in filter chains, where the order of filter execution is defined by the order of registration. Web Filter instances may configured through init parameters.

Example code
In the test example below, the Web Component TExamplePage returns the plain-text response "example", and the filters (TTestFilterA and TTestFilterB) add the texts " (A)" and " (B)" to the response. The client therefore receives the response "example (A) (B)".
 

Code: Pascal  [Select][+]
  1. procedure TAPIConfigTests.TestTwoFilters;
  2. var
  3.   Server: TdjServer;
  4.   Context: TdjWebAppContext;
  5. begin
  6.   Server := TdjServer.Create;
  7.   try
  8.     Context := TdjWebAppContext.Create('web'); // Context located at http://<server:port>/web/
  9.     Context.AddWebComponent(TExamplePage, '*.txt'); // Web Component responds to all requests for txt documents
  10.     Context.AddWebFilter(TTestFilterA, TExamplePage); // Web Filter A will be processed first and appends " (A)"
  11.     Context.AddWebFilter(TTestFilterB, TExamplePage); // Web Filter B will be processed second and appends " (B)"
  12.     Server.Add(Context);
  13.     Server.Start;
  14.  
  15.     CheckGETResponseEquals('example (A) (B)', '/web/test.txt');
  16.  
  17.   finally
  18.     Server.Free;
  19.   end;
  20. end;
  21.  



 

Code for the DoFilter method of TTestFilterA:

 

procedure TTestFilterA.DoFilter(Context: TdjServerContext; Request: TdjRequest;
  Response: TdjResponse; const Chain: IWebFilterChain);
begin
  Chain.DoFilter(Context, Request, Response);  // invoke other filters and eventually the Web Component 
  Response.ContentText := Response.ContentText + ' (A)';
end;

 

Full source code, including DUnit and FPCUnit tests, is available at GitHub. The Web Filter API specification is still in development and may still see minor and major changes.

More information
- GitHub: https://github.com/michaelJustin/daraja-framework
- 2.6-SNAPSHOT API documentation: https://michaeljustin.github.io/daraja-framework/2.6-SNAPSHOT/
- Project home page: https://www.habarisoft.com/daraja_framework.html

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×