This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
docu_http [2018/08/06 17:59] Niek created |
docu_http [2018/08/18 11:35] Niek [Options for GET] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Send an http(s) GET or POST request===== | + | =====Send an http(s) GET or POST request and receive response in a generic_label===== |
====Options for GET==== | ====Options for GET==== | ||
- | |||
- | |<100% 50px 50px 50px 200px>| | ||
^Name^Required^Multiple Values^Description^ | ^Name^Required^Multiple Values^Description^ | ||
|GET|yes|no|The url for a GET request| | |GET|yes|no|The url for a GET request| | ||
- | |PARAM|no|no|An optional parameterstring for a GET request| | + | |DEVICE|no|no|A generic_label device to receive the response| |
====Options for POST==== | ====Options for POST==== | ||
Line 13: | Line 11: | ||
^Name^Required^Multiple Values^Description^ | ^Name^Required^Multiple Values^Description^ | ||
|POST|yes|no|The url for a POST request| | |POST|yes|no|The url for a POST request| | ||
- | |PARAM|yes|no|A parameterstring required for a POST request| | + | |DATA|yes|no|A parameterstring required for a POST request| |
|MIMETYPE|yes|no|The mimetype required for a POST request| | |MIMETYPE|yes|no|The mimetype required for a POST request| | ||
+ | |DEVICE|no|no|A 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: | ||
+ | |||
+ | <code> | ||
+ | "mylabel": { | ||
+ | "protocol": [ "generic_label" ], | ||
+ | "id": [{ | ||
+ | "id": 1 | ||
+ | }], | ||
+ | "label": "hello world", | ||
+ | "color": "code=200&size=11&mimetype=text/plain" | ||
+ | }, | ||
+ | </code> | ||
+ | |||
+ | 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: | ||
+ | |||
+ | <code> | ||
+ | "mylabel": { | ||
+ | "protocol": [ "generic_label" ], | ||
+ | "id": [{ | ||
+ | "id": 1 | ||
+ | }], | ||
+ | "label": "hello world", | ||
+ | "color": "code=408&size=0" | ||
+ | }, | ||
+ | </code> | ||
+ | |||
+ | The code, size and mimetype can be individually extracted using the [[docu_extract| EXTRACT]] function like this: | ||
+ | |||
+ | <code> | ||
+ | EXTRACT(mylabel.color, code) returns code | ||
+ | EXTRACT(mylabel.color, size) returns size | ||
+ | EXTRACT(mylabel.color, mimetype) returns mimetype (if present) | ||
+ | </code> | ||
+ | |||
+ | If no device is given, the result of the http request is ignored. | ||
====Examples==== | ====Examples==== | ||
Line 20: | Line 67: | ||
<code> | <code> | ||
IF 1 == 1 THEN http GET 'http://www.somewebsite.com/' | 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 GET 'https://www.somewebsite.com/' PARAM 'command=show&format=xml' | + | 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 POST 'http://www.somewebsite.com/' PARAM 'command=show' MIMETYPE 'text/plain' | + | IF 1 == 1 THEN http GET 'http://192.168.1.1/myserver/' |
- | | + | </code> |
- | 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: | ||
+ | |||
+ | <code> | ||
+ | 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) | ||
</code> | </code> | ||