...
qs
— a map that will be used to create the URI encoded query parametersheaders
— a map with additional http headers- body — a raw string for the http body
- auth — a optional map with keys
"username"
and"password"
which is used to add a basic authentication header to the request - json — data to encode the http body as json, also setting the `application/json` header (this parameter is ignored if body is provided)
- form — a map to encode as `application/x-www-form-urlencoded`, also setting that header (this parameter is ignored if body or json is provided)
- parseJSON — set this to true if you want to try to parse the `content` as json
- autoraise — a string that will be the label applied to the event that this action automatically raises.
- autosend — a map like the map specifying an event to be sent in
event:send
(see documentation of the event library). It specifies the Event Channel Identifier (ECI), and the domain and type of an event to be added to a pico's queue when the HTTP response becomes available. Note that this will happen in a separate transaction. The pico to receive the response event must be hosted on the same pico engine.
The action supports an optional setting
clause that gives the name of the variable in which the response to the HTTP request should be stored for later use. This variable is available to any expression executed after the action takes place: expressions in the parameters of later actions or in the postlude of the rule.
The resulting map of name-value pairs has the following structure:
content
— the content of the responsecontent_type
— the MIME type of the contentcontent_length
— the number of bytes in the contentheaders
— a map with all the response headersstatus_code
— the three digit HTTP status codestatus_line
— the complete status string including the three digit HTTP status codelabel
— the autoraise label, if autoraise is set (see above)
The following example shows using an http:post()
action inside a rule:
...
Code Block | ||||
---|---|---|---|---|
| ||||
json_from_url = http:get(my_url){"content"}.decode() |
Processing the Response
With autosend
If autosend
is set, the rule will complete evaluation, and at a later time, when the server at the URL returns its response, the event specified will be generated and added to the queue of the pico which provides the channel matching the ECI included in the autosend
map.
With autoraise
If autoraise
is set, the rule will automatically raise an event with the event domain http
and the event type equal to the HTTP method used (i.e. post
, put
, get
, delete
). The event will contain attributes with the same name-value structure that HTTP actions and function return.
...