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 )
mjn
source share