Can anyone explain PATCH HTTP method (POST)?
Last Post 28 Jan 2013 11:41 AM by Greg Wilburn. 5 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Greg Wilburn
Basic Member
Basic Member
Posts:235

--
21 Jan 2013 12:51 PM

I'm using the HTTPAPIR4 service pgm to retrieve orders from a website... they have recently added functionality that allows me to "update" those orders that I have retrieved.  I'm supposed to do this using the PATCH HTTP method.

The site supports XML and JSON (I'm retrieving using the XML resource), but their example is in JSON. 

I'm thinking an XML document with the appropriate "PATCH HTTP" header along with the XML data to be updated - but I'm not sure about the header.

I am not a web programmer, so any insight would be appreciated.

Emmanuel
Veteran Member
Veteran Member
Posts:818

--
21 Jan 2013 12:56 PM

Perhaps this might help:

http://www.freeformatter.com/json-t...erter.html

Cheers,

Emmanuel

Greg Wilburn
Basic Member
Basic Member
Posts:235

--
22 Jan 2013 07:56 AM
Thanks Emmanuel, but I only have a snippet of the JSON code. I'm just wondering if this can be done using the service program (HTTPAPIR4) that I'm already familiar with. From the limited information I've gathered on "PATCH HTTP", I'm thinking the http_post may not work.
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16386
Avatar

--
26 Jan 2013 09:12 AM

This is a new one for me..   the PATCH method is an extension to HTTP that I haven't run across before.

Having said that, the latest version of HTTPAPI (and I recommend using the BETA) does have a lower-level routine called http_persist_req() that theoretically would work with PATCH.  It's a little lower-level routine that http_post() so you'd need to fill in some additional parameters, and possibly write a bit more code on your end to use it, but may do the trick.

The idea will be to:

  • Call http_persist_open() to start the connect.  This returns something that I call a "communications session", which is really just something you need to pass on to persist_req() so it knows how to communicate.
  • Call http_persist_req().   Pass the first parameter as 'PATCH', then the comm session, and the URL.  (For various reasons I won't get into here, you have to pass the URL to both persist_open and persist_req) Here you'll have to figure out how to handle sending/receiving the data.  You can either use a pointer to the data to send, along with a length, or you can have a call-back routine that does something like read a file.  Unfort, this low-level routine does not support giving just a filename.  For receiving the response, you must also use a call-back routine.  Again, unfort, it does not support retrieving to a variable or file, you have to write that logic yourself.
  • Finally, call http_persist_close().   Calling these three routines (open, req, close) together is equivalent to calling something like http_post() or http_post_raw(), except of course, you're not locked into GET or POST, you can do other things, like PATCH.

Good luck

Henrik Rutzou
Advanced Member
Advanced Member
Posts:601
Avatar

--
27 Jan 2013 05:35 AM

Hi Greg,


If it is at any help, you can mix Scott's LIBHTTP with the JSON READ/WRITE subprocedures in powerEXT Core


Greg Wilburn
Basic Member
Basic Member
Posts:235

--
28 Jan 2013 11:41 AM
Posted By Scott Klement on 26 Jan 2013 10:12 AM

This is a new one for me..   the PATCH method is an extension to HTTP that I haven't run across before.

Having said that, the latest version of HTTPAPI (and I recommend using the BETA) does have a lower-level routine called http_persist_req() that theoretically would work with PATCH.  It's a little lower-level routine that http_post() so you'd need to fill in some additional parameters, and possibly write a bit more code on your end to use it, but may do the trick.

The idea will be to:

  • Call http_persist_open() to start the connect.  This returns something that I call a "communications session", which is really just something you need to pass on to persist_req() so it knows how to communicate.
  • Call http_persist_req().   Pass the first parameter as 'PATCH', then the comm session, and the URL.  (For various reasons I won't get into here, you have to pass the URL to both persist_open and persist_req) Here you'll have to figure out how to handle sending/receiving the data.  You can either use a pointer to the data to send, along with a length, or you can have a call-back routine that does something like read a file.  Unfort, this low-level routine does not support giving just a filename.  For receiving the response, you must also use a call-back routine.  Again, unfort, it does not support retrieving to a variable or file, you have to write that logic yourself.
  • Finally, call http_persist_close().   Calling these three routines (open, req, close) together is equivalent to calling something like http_post() or http_post_raw(), except of course, you're not locked into GET or POST, you can do other things, like PATCH.

Good luck

Thanks for the explanation... When I find time to get back to this project, I will definitely give this a try.  I use the heck out of the HTTPAPI tools (and CGIDEV2).

Incidentally, I'm communicating with something called Handshake App. if anyone else runs into this.  The PATCH method is documented, but was provided to me by their tech support.


 

You are not authorized to post a reply.

Acceptable Use Policy