http "PATCH" method

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
mmayer4
Posts: 13
Joined: Sun Jul 10, 2022 1:07 pm

http "PATCH" method

Post by mmayer4 »

I've run into my first requirement of an API that requires "PATCH" instead of "post". So I Googled the following in AI_mode: on IBM i in ILERPG using Scott Klement's HTTPAPI service program, is it possible to use PATCH instead of POST.

It said, Yes! Use http_xproc() with HTTP_POINT_SET_METHOD constant to specify "PATCH" as the method to be used. The you can use http_url_post() and it will use the PATCH method instead of post.

So I said, Sweet! that's easy! Well, it lied :( There is no HTTP_POINT_SET_METHOD constant.

So the question remains, is there a way to use PATCH with http_url_post() ? Or another way to send a JSON body with a bearer token authorization?

What I had hoped for was the following:

Code: Select all

http_setCCSIDs( 1208: 0 );
http_setauth(HTTP_AUTH_BEARER  : ' ' : bearerToken);
http_xproc(HTTP_POINT_SET_METHOD: 'PATCH');

rc = http_url_post( url 
                  : %addr(jsonBuf : *data)
                  : %len(jsonBuf)
                  : ifsResp
                  : HTTP_TIMEOUT
                  : HTTP_USERAGENT
                  : 'application/json');
User avatar
tools400
Posts: 6
Joined: Thu Jul 29, 2021 4:56 am

Re: http "PATCH" method

Post by tools400 »

Did you alread try the http_req() procedure? It looks as if it could do the job, if you specify 'PATCH' for the first parameter 'Type':

Code: Select all

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  HTTP_req(): Perform any HTTP request and get input/output from
      *              either a string or an IFS stream file.
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P http_req        B                   export
     D                 PI            10i 0 opdesc
     D   Type                        10a   varying const
     D   URL                      32767a   varying const
     D   ResultStmf                5000a   varying const
     D                                     options(*varsize:*omit)
     D   ResultStr                     a   len(16000000) varying
     D                                     options(*varsize:*omit:*nopass)
     D   SendStmf                  5000a   varying const
     D                                     options(*varsize:*omit:*nopass)
     D   SendStr                       a   len(16000000) varying const
     D                                     options(*varsize:*omit:*nopass)
     D   ContentType              16384A   varying const
     D                                     options(*varsize:*omit:*nopass)
mmayer4
Posts: 13
Joined: Sun Jul 10, 2022 1:07 pm

Re: http "PATCH" method

Post by mmayer4 »

I saw that but didn't think it would fit my needs. Can't hurt to try. I will code it up and see if it works and report back. Thanks.
Scott Klement
Site Admin
Posts: 925
Joined: Sun Jul 04, 2021 5:12 am

Re: http "PATCH" method

Post by Scott Klement »

There is no HTTP_POINT_SET_METHOD -- and frankly, it doesn't make any sense.

Stop using the old school http_url_post() routine, please. You can set the method with http_req(), but even if you were using POST, I would strongly recommend using http_req() instead of http_url_post()!
mmayer4
Posts: 13
Joined: Sun Jul 10, 2022 1:07 pm

Re: http "PATCH" method

Post by mmayer4 »

the http_req() worked! Thank y'all so much!

@Scott, Just out of curiosity/education purposes, why do you consider the http_url_post() routine "old school".
Scott Klement
Site Admin
Posts: 925
Joined: Sun Jul 04, 2021 5:12 am

Re: http "PATCH" method

Post by Scott Klement »

http_url_post() was one of the earlier routines I added back in 2001. After years of using this and others like http_url_post_raw, http_url_get, http_url_get_raw, I wrote http_req() in 2015 to be better, easier, more powerful, more versatile.

In my experience, the only reason people use the old routines today is because they have an old program, or found an old example.

You'll be much happier using http_req(), http_string() or http_stmf()
mmayer4
Posts: 13
Joined: Sun Jul 10, 2022 1:07 pm

Re: http "PATCH" method

Post by mmayer4 »

Gotcha.. Thanks again for everything you do!
Post Reply