Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST server in Delphi XE2 pro

I had a (very simple) self made REST server embeded in my application in Delphi 7 (with ICS + some stuf), it works but is not easy to maintain & extend. Now I use Delphi XE2 Pro (without DataSnap) and I would change for a more standard solution, but yet simple.

Is there a nice easy of doing this?

like image 545
philnext Avatar asked May 10 '12 13:05

philnext


2 Answers

The Habari Web Components framework is a simple (commercial) HTTP server framework for Delphi 2009 and newer. With the TdjRestfulComponent it also includes a REST extension. (I am the developer of these libraries)

TdjRestfulComponent configuration can be done in an attribute/annotation-like style or in a more traditional procedural style way.

All HTTP methods and content-types can be mapped to different anonymous methods, and still share the same resource URI (one URI, different resource representations - depending on the requested content type). For example, to represent the resource /myresource in HTML, XML or JSON, it can be configured like this:

// respond to HTML browser GET request
&Path('myresource');
&Produces('text/html');
GET(procedure(Request: TRequest; Response: TResponse)
 begin
   Response.ContentText := '<html>Hello world!</html>';
 end);

// respond to XML client
&Path('myresource');
&Produces('application/xml');
GET(procedure(Request: TRequest; Response: TResponse)
  begin
    Response.ContentText := '<xml>Hello world!</xml>';
  end);

// respond to JSON client
&Path('myresource');
&Produces('application/json');
GET(procedure(Request: TRequest; Response: TResponse)
  begin
    Response.ContentText := '{"msg":"Hello world!"}';
  end);

The component also supports path parameters:

&Path('orders/{orderId}/lines/{lineNo');

will parse a URL like

http://mydomain.local:8080/context/orders/65432/lines/1

into additional query parameters (orderId=65431 and lineNo=1)

like image 149
mjn Avatar answered Oct 12 '22 03:10

mjn


I do not know if it is as simple as required, but you may take a look at our mORMot framework.

This is a whole RESTful server, with a Client-Server ORM, and an interface-based services (like WCF). It is light and fast, but also has a lot of features.

You can do whatever kind of applications you want. For instance, some users do not use its ORM, nor its SOA, but just use it as a very fast RESTful server.

It works with any version of Delphi, from Delphi 6 up to XE2, and does NOT require a particular license: it would work also with the Starter edition. Even the database connections are included.

It is not a "standard" by itself, but it uses well-known standards, like REST, HTTP, JSON. It has per-URI build-in authentication, and a whole per-interface / per-method security policy. More than 800 pages of documentation, and a full set of regression tests included. For a quick start, take a look at the samples - I suspect you may find it easy.

And it is free like a beer, and like a bird.

like image 27
Arnaud Bouchez Avatar answered Oct 12 '22 04:10

Arnaud Bouchez