REST server in Delphi XE2 pro

I had a (very simple) REST server itself, built into my application in Delphi 7 (with ICS + some stuf), it works, but it is not easy to maintain and extend it. Now I am using Delphi XE2 Pro (without DataSnap), and I would change for a more standard solution, but still simple.

Is it easy to do?

+7
source share
2 answers

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

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

All HTTP methods and content types can be mapped to different anonymous methods and still use the same URI (one URI, different resource representations, depending on the type of requested content). For example, to represent a /myresource resource in HTML, XML, or JSON, you can configure it as follows:

 // 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 the url for example

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

in additional request parameters ( orderId=65431 and lineNo=1 )

+6
source

I don't know how simple it is, but you can take a look at our mORMot structure .

This is a complete RESTful server with client server ORM and interface-based services (e.g. WCF). It is lightweight and fast, but also has many features.

You can make any applications you want. For example, some users do not use their ORM or its SOA, but simply use it as a very fast RESTful server.

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

This is not a "standard" in itself, but it uses well-known standards such as REST, HTTP, JSON. It has built-in authentication for each URI and an entire security policy for each interface. Over 800 pages of documentation and a complete set of regression tests are included. For quick start, take a look at the samples - I suspect it might be easy for you.

And it's free, like beer, and like a bird.

+2
source

All Articles