Programming => Networking and Web Programming => Topic started by: Almir Lima on May 25, 2019, 06:25:31 pm

Title: [SOLVED] Verbs HTTP
Post by: Almir Lima on May 25, 2019, 06:25:31 pm
Hy everyone,
I want send others verbs in HTTP like PUT PATCH DELETE with Synapse, but i cannot find.
Title: Re: Verbs HTTP
Post by: Almir Lima on May 26, 2019, 03:59:57 am
The goal is do a API and use all RESTFUL verbs.

I solved this creating a clone function of the Synapse HttpSend with a little modify: "A option for alter the Verbs to send a request."

I tested  in NodeJS, and everything worked perfect.

This the code.

Code: Pascal  [Select][+][-]
  1. function Http_Send(const Verb, URL: string; const Data: TStream
  2.   ): Boolean;
  3. var
  4.   HTTP: THTTPSend;
  5. begin
  6.   HTTP := THTTPSend.Create;
  7.   try
  8.     HTTP.Document.CopyFrom(Data, 0);
  9.     HTTP.MimeType := 'Application/octet-stream';
  10.     Result := HTTP.HTTPMethod( Verb, URL);
  11.     Data.Size := 0;
  12.     if Result then
  13.     begin
  14.       Data.Seek(0, soFromBeginning);
  15.       Data.CopyFrom(HTTP.Document, 0);
  16.     end;
  17.   finally
  18.     HTTP.Free;
  19.   end;
  20. end;
Title: Re: [SOLVED] Verbs HTTP
Post by: lucamar on May 26, 2019, 09:27:19 am
A friendly reminder: When talking about networking you should have a care how you use the terminology, lest confussion arises.

Those "verbs" you talk about have little to do with RESTful APIs, but with WEBDAV. See here: WebDAV Ressources (

Also, if you want to build a generic solution you should add a functions to send multipart- in addition to URL-encoded  requests. Most Web APIs I know of expect them, since they deal with relatively big objects (documents, images, etc.) that can't be encoded in the URL.

For example, here's how we defined some net-helpers when we built our (Delphi) Flickr API objects:
Code: Pascal  [Select][+][-]
  1. { Calls to Web Sites' APIs like p.e. Flickr's }
  2. {HTTP service request--url-encoded params
  3.  Make a request using HTTP Method, passing parameters
  4.  @code(Params) in url-encoded form. }
  5. function WebMethodCall(const BaseURL: String; Params: TStrings;
  6.                        Method: TReqMethod = rqPost): String; overload;
  7. {HTTP service request--w/out params
  8.  Make a request using HTTP Method passing no parameters
  9.  (unless already encoded by the user in @code(BaseURL).}
  10. function WebMethodCall(const BaseURL: String;
  11.                        Method: TReqMethod = rqPost): String; overload;
  12. {HTTP service request--Multipart/Form-Data
  13.  Make a request using HTTP POST and passing parameters
  14.  as a Multipart/Form-Data stream.
  15.  Used, generally, to upload a file to a server.
  16.  }
  17. function WebMethodCall(const BaseURL: String;
  18.                        FormData: TIdMultiPartFormDataStream): String; overload;
TinyPortal © 2005-2018