httppostapldyalog

How do I POST raw data in Dyalog APL HttpCommand?


I am trying to submit data as plain text using HttpCommand object. I know how to do it with cURL, but I'm unsure how to specify the data in my HttpCommand object. Here's how I would do it with cURL:

curl -request POST "http://my-api-url" --header "Content-Type: text/plain" --data-raw "here is my test"

What's the equivalent way to send the plain text data in my HttpCommand object?


Solution

  • The most direct analogous HttpCommand equivalent is:

          r←HttpCommand.Do 'post' 'http://my-api-url' 'here is my test' ('content-type' 'text/plain')
    

    The basic syntax for HttpCommand.Do is:

          r←HttpCommand.Do 'Command' 'URL' Params Headers 
    

    r will be a namespace containing information about the response.
    r.rc is the return code where 0 indicates your request was successfully sent and a response receieved.
    r.HttpStatus is the HTTP status code. A 2XX status means that the request was successful.
    r.Data is the response payload (body), if any was sent by the server.
    r.Headers is a 2-column matrix of the response's HTTP header name/value pairs.
    r contains other elements as well.

    There are other ways to accomplish the same task using HttpCommand that may be useful - for instance if you want to issue multiple requests to the same host.

    These are all covered in the HttpCommand documentation