While writing a Delphi Rich client for a personal project talking to RESTful service I recently became frustrated with the available easy REST client interfaces for Delphi.
As a result, I wrote a small wrapper around the Indy TIdHttp component to provide a fluent interface upon which you can use to write REST clients. It’s lightweight wrapper, which currently only has the functionality that I required for this project but I decided to make it available in case anyone else wanted to use it.
You can view a simple example were we post a fictional example of PUT’ing a todo item below:
program SimpleRestRequestSample;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Classes,
RestRequest in 'RestRequest.pas';
var RestReq: TRestRequest;
RestResp: THttpResponse;
putParams: TStringList;
begin
try
try
putParams := TStringList.Create();
putParams.Add('title=Buy milk');
putParams.Add('due-date=01/01/2013 00:00:00');
RestReq := TRestRequest.Create().Domain('localhost').Path('todo').WithCredentials('test', 'test');
RestResp := RestReq.Put(putParams);
if RestResp.ResponseCode = 200 then WriteLn('Your todo was added!');
finally
RestReq.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
As you can see, the interface is designed to be fluent to make it easy to see the components of the request in your code.
The TRestResponse record that is returned contains the ResponseCode and the ResponseBody but does nothing with the returned body as the type of response will be determined by your Client and Server. For example, in my own client project, I set the Accept header to prefer ‘application/json’ and then parse this in the response after receiving a 200 OK response from the server with the application/json header,. This looks something like the below:
request := TRestRequest.Create.Domain(Self.FAPIEndPoint).WithCredentials(Self.FUsername, Self.FPassword).Path('todo').Path(IntToStr(id));
response := request.Get;
if response.ResponseCode = 200 then
begin
result := jsonToObj(response.ResponseStr);
Self.doOnTodoReturned(result);
end else Self.doOnErrorStatus(response.ResponseCode, response.ResponseStr);
There are a few limitations: for example, it doesn’t currently support the PATCH method as TIdHttp doesn’t currently support this method and I didn’t have the time or motivation to mock out TIdHttp so the unit test coverage doesn’t currently extend that far. Aside from that, I’ve found it pretty nice to work with in my own project so any thoughts would be appreciated.
I’m completely open to help or contributions and you can view the SimpleRestClient project on Github.

Jamie is a Software Development manager, Team Lead, Technical product owner and General Geek. In my spare time I develop in Delphi, Ruby, Python, C# and JVM languages (Java, Clojure). I am an enthusiastic advocate of hobbyist development and in particular tools which allow for hobbyist development. I am also extremely passionate about Continuous Delivery. Please have a good look around and enjoy anything that you find useful on this site. 

Nice idea but wrapper sekund WinHttp would be better.
Some time ago I was searching for a Rest Client for Delphi also, but i’m not found, and i began to develop a project.
Take a look: https://github.com/fabriciocolombo/delphi-rest-client-api
Cool, some nice code to make things easier. You can’t beat that!
@Pos: Interesting option.
@Fabricio Colombo: Ooh, interesting, it’s rather more fully featured!
@ObjectMethodology.com: Thanks!
You may also keep some ideas from the REST client part of MORMot :
http://synopse.info/fossil/wiki/Synopse+OpenSource
@Phil: I haven’t seen the MORMot framework yet but it looks like Fabricio’s framework.
Is it possibile upload zip file in the the post parameters?
function Param(aKey: string; aValue: string): TRestRequest;
Param function accepts string values for the Keys and not object
Thanks in advance
@Dall’Ara Luca: It presently only supports “application/x-www-form-urlencoded” encoded params, the presence of a file would mean switching automatically to “multipart/form-data” encoding. Certainly do-able, but will require modifications. I’ve opened an issue on the github project at: https://github.com/jamiei/SimpleRestClient/issues/1
I’ll use the issue for tracking.
Thank you very much!