3

This question is in regards to an application being build in Delphi XE5.

I am working with a third party to provide an application that allows users to update information, JSON formatted, through a HTTP post to the third party's API. If I separate the user information into single objects I can use the POST method, but due to the amount if individual events the process is slow. It's much faster if I perform a batch post of a file containing multiple objects but api requires that I use the PATCH verb when uploading a file vs single object. I can do so using curl, but I want to avoid having to install curl on every users system to do so.

Is there any way to utilize the PATCH verb in Delphi? It does not seem that Indy has PATCH supported.

La-comadreja
  • 5,627
  • 11
  • 36
  • 64
psulion
  • 33
  • 3

2 Answers2

5

If you are using an up-to-date version of Indy 10, TIdHTTP has 2 overloaded Patch() methods, and a Response.AcceptPatch property, that were added 5 months ago (for use in Embarcadero's REST client):

procedure Patch(AURL: string; ASource, AResponseContent: TStream);
function Patch(AURL: string; ASource: TStream): string;

property AcceptPatch: string;

If you are using an older version of Indy, you can call the TIdHTTP.DoRequest() method to send requests using custom verbs. It is declared as protected, so you will have to use an accessor/descendant class to reach it, eg:

type
  TIdHTTPAccess = class(TIdHTTP)
  end;

TIdHTTPAccess(IdHTTP1).DoRequest('PATCH', URL, SourceData, nil, []);
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I'm using an older version and the second method fixed my issue, thank you very much. – psulion Jul 03 '14 at 15:43
  • Using the version of Indy that ships with XE7, the Patch() method is not listed in the help that ships with XE7, but the Patch method IS available for use. – nachbar Nov 15 '14 at 03:18
  • That is because Indy's documentation is not up-to-date. A lot of changes/features have been added since the last time the documentation was updated. – Remy Lebeau Nov 15 '14 at 03:47
0

Only completing this information, follow example bring return from api:

    AStrRequest := TStringStream.Create('your json to send');
    AStrResponse := TStringStream.Create;

    TIdHTTPAccess(http).DoRequest('PATCH', FURL, AStrRequest, AStrResponse,[]);