tags:

views:

712

answers:

3

Title says it all, I need to send PUT and DELETE along with POST, GET to a REST API how can I do it?

A: 

Check out the ICS components, they are suitable for the job.

Drejc
+6  A: 

Delphi 7 comes with Indy. See the TIdHTTP component and specificly the Get and Put methods.

Lars Truijens
+3  A: 

Or look at the open source Synapse library. There are some simple function calls in the HTTPSend unit which make implementing this completely painless. Just use the sample functions/procedures as your model for the PUT/DELETE. The existing routines already supply the POST and GET. The difference is in the method passed.

Personally I have found this library to be perfectly matched for working with REST. Its simple, well written and easy to extend.

For example, here is a simple put that sends and receives a stream:

function HttpPutBinary(const URL: string; const Data: TStream): Boolean;
var
  HTTP: THTTPSend;
begin
  HTTP := THTTPSend.Create;
  try
    HTTP.Document.CopyFrom(Data, 0);
    HTTP.MimeType := 'Application/octet-stream';
    Result := HTTP.HTTPMethod('PUT', URL);  // changed method from 'POST'
    Data.Size := 0;
    if Result then
    begin
      Data.Seek(0, soFromBeginning);
      Data.CopyFrom(HTTP.Document, 0);
    end;
  finally
    HTTP.Free;
  end;
end;
skamradt