ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

New QSYS2 HTTP Functions: Converting SYSTOOLS XML Header to Json Version

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • New QSYS2 HTTP Functions: Converting SYSTOOLS XML Header to Json Version

    I am curious how to convert the following systools.httppostclob header from...

    Code:
    <httpHeader connectionTimeout="10000" readTimeout="10000"  includeErrorMsg="true">
    <header name="Content-Type" value="application/json"/>
    <header name="Authorization-key" value="xyz123"/>
    <header name="Authorization-Username" value="xyz123"/>
    </httpHeader>
    ...to the new qsys2.http_post header in json format. I believe this is it, but I cannot find the equivalent of includeErrorMsg="true"

    Code:
    {
      "header":"connectTimeout, 10000"
     , "header":""ioTimeout, 10000"
     , "header":"signalErrors, true"
    }
    Is this correct?

    When reviewing the following page for http options for the new QSYS2 http functions, it does not specify how to specify a header values that are xml attributes (ie. connectionTimeout in httpHeader).


    The HTTP_GET or HTTP_GET_BLOB scalar function retrieves a text-based resource from the specified URL through an HTTP GET request.



    Thoughts?

  • #2
    I haven't had a chance to try them, but the page you pointed to seems to say that you just specify them in normal JSON format

    Code:
    {
      "connectTimeout": 10000,
      "ioTimeout": 10000,
      "signalErrors: true
    }

    Comment


    • #3
      Or, if you wanted the headers as well:

      Code:
      {
        "header": "Content-Type, application/json",
        "header": "Authorization-key, xyz123",
        "header": "Authorization-Username, xyz123",
        "connectTimeout": 10000,
        "ioTimeout": 10000,
        "signalErrors: true
      }

      Comment


      • #4
        Thanks Scott.


        Just to confirm. The <httpHeader> attributes for the new http functions are formatted exactly the way most json value pairs are formatted:

        Code:
        {
          "connectTimeout": 10000
          , "ioTimeout": 10000
          , "signalErrors: true
        }
        But any separate header nodes (in xml format) are specified in a new custom format of:

        "header" : "<headerName>, <headervalue>"

        Am I reading this correctly?

        Comment


        • #5
          Originally posted by TheZenbudda View Post
          Thanks Scott.
          Just to confirm. The <httpHeader> attributes for the new http functions are formatted exactly the way most json value pairs are formatted:
          [SNIP]
          But any separate header nodes (in xml format) are specified in a new custom format of:
          [SNIP]
          The connection timeout, IO timeout and whether errors are/aren't reported are NOT http headers. In the HTTP protocol, a header is a specific type of item that is transferred over the network. A connection timeout is a setting used by the client to determine how long it waits for the network, it's not something it actually sends to the server. Same for an IO timeout. And whether the client reports errors to your program or not has nothing to do with what is or isn't sent over a network.

          So none of those are headers. They are just settings for how the HTTP client works.

          The old format where they were specified as part of an <httpHeader> XML tag was strange, because they aren't headers, and it wouldn't make sense for them to be.

          The new format is much more logical. It is a JSON document and is in standard JSON syntax, but it essentially takes this format:

          Code:
          {
            "setting-name": "setting-value",
            "another-setting-name": "another-setting-value",
            ...etc...
          }
          So it makes perfect sense that you'd specify the http client settings that way:
          Code:
          {
            "connectTimeout": 10000,
            "ioTimeout": 10000,
            "signalErrors: true
          }
          In order to provide you with a way to send an http header, they added a setting called "header" (which you can specify multiple times if needed). Since an HTTP header has two parts, the header name and it's value, you specify it as a comma-separated string:
          Code:
            "header": "name-of-header, value-of-header"
          So to specify the connection timeout, IO timeout, whether to signal errors, and 3 http headers, you can do it like this:
          Code:
          {
            "header": "Content-Type, application/json",
            "header": "Authorization-key, xyz123",
            "header": "Authorization-Username, xyz123",
            "connectTimeout": 10000,
            "ioTimeout": 10000,
            "signalErrors: true
          }

          Comment


          • #6
            Scott,

            I confirmed that even though the documentation suggests that connectTimeout and ioTimeout are numeric, you actually have to declare the value as character (including boolean values):

            Code:
            {
            "header": "Content-Type,application/json",
            "header": "Authorization-key, xyz123",
            "header": "Authorization-Username, xyz123",
            "connectTimeout": "10000",
            "ioTimeout": "10000",
            "signalErrors: "true"
            }

            Comment


            • #7
              Originally posted by TheZenbudda View Post
              I confirmed that even though the documentation suggests that connectTimeout and ioTimeout are numeric, you actually have to declare the value as character (including boolean values):
              That's a weird design choice on IBM's part... but it seems like it'd be relatively easy to work with. Is there a particular reason you're pointing it out to me?

              Comment

              Working...
              X