User Tools

Site Tools


docu_http

Send an http(s) GET or POST request and receive response in a generic_label

Options for GET

NameRequiredMultiple ValuesDescription
GETyesnoThe url for a GET request
DEVICEnonoA generic_label device to receive the response

Options for POST

NameRequiredMultiple ValuesDescription
POSTyesnoThe url for a POST request
DATAyesnoA parameterstring required for a POST request
MIMETYPEyesnoThe mimetype required for a POST request
DEVICEnonoA generic_label device to receive the response

Description

The http action can perform hhp(s) GET and POST requests. It can optionally be used with a generic_label device to store the response of the request.

If a device is given. the label- and color fields of the label device are respectively being used to store the received data and the corresponding code, size and mimetype.

While the http request in in progress, the color field is set to “busy”. During that time any new http request for the same device will be skipped.

When the http action completes the new response data is stored in the label field and the color is set to the code size and mimetype of the response.

Because the color first changes to “busy” and then, when the request finishes, to response code, size and mimetype, the color can be used to trigger other rules.

Typically, after a succesfull request, the label will look something like this:

 "mylabel": {
 	"protocol": [ "generic_label" ],
 		"id": [{
 			"id": 1
 		}],
		"label": "hello world",
 		"color": "code=200&size=11&mimetype=text/plain"
 },

The label field always contains the data received from the latest successfull request. So, suppose the next request would time out, the label will look like this:

 "mylabel": {
 	"protocol": [ "generic_label" ],
 		"id": [{
 			"id": 1
 		}],
		"label": "hello world",
 		"color": "code=408&size=0"
 },

The code, size and mimetype can be individually extracted using the EXTRACT function like this:

EXTRACT(mylabel.color, code) returns code
EXTRACT(mylabel.color, size) returns size
EXTRACT(mylabel.color, mimetype) returns mimetype (if present)

If no device is given, the result of the http request is ignored.

Examples

   IF 1 == 1 THEN http GET 'http://www.somewebsite.com/'

   IF 1 == 1 THEN http GET 'http://www.somewebsite.com/' DEVICE mylabel

   IF 1 == 1 THEN http GET 'https://www.somewebsite.com/?command=show&format=xml' DEVICE mylabel
   
   IF 1 == 1 THEN http POST 'http://www.somewebsite.com/' DATA 'command=show&format=xml' MIMETYPE 'text/plain' DEVICE mylabel

   IF 1 == 1 THEN http GET 'http://192.168.1.1/myserver/'

If a device is given, other rules can be triggered using the change of the color field:

   IF mylabel.color != busy THEN label mylabel2 TO 'The http action has finished' 

   IF mylabel.color != busy THEN label mylabel2 TO 'The code is ' . EXTRACT(mylabel.color, code) 
docu_http.txt · Last modified: 2018/08/18 13:35 by Niek