Request module written using the Go language. This module can be used to make HTTP(S) requests with ThingsDB.
Install the module by running the following command in the @thingsdb
scope:
new_module('requests', 'github.com/thingsdb/module-go-requests');
Optionally, you can choose a specific version by adding a @
followed with the release tag. For example: @v0.1.0
.
This module does not require any config.
Name | Description |
---|---|
get | Make a GET request. |
post | Make a POST request. |
post_json | Make a JSON POST request. |
Syntax: get(url, options)
url
: The URL to make the GET request to.options
: Thing with properties to add to the GET request.
requests.get("https://reqbin.com/echo").then(|res| {
res; // just return the response.
});
Syntax: post(url, body, options)
url
: The URL to make the POST request to.body
: Body to send with the request (as bytes).options
: Thing with properties to add to the POST request.
For an example, see post_json below.
Syntax: post_json(url, body, options)
Like post, except that the headers will be set to accept and send JSON data.
url
: The URL to make the POST request to.body
: Body to send with the request (as bytes).options
: Thing with properties to add to the POST request.
record = {
Id: 78912,
Customer: "Jason Sweet",
Quantity: 1,
Price: 18.00
};
requests.post_json("https://reqbin.com/echo/post/json", json_dump(record)).then(|res| {
res = res.load();
json_load(str(res.body));
});
Option | Type | Description |
---|---|---|
method |
str | Method to use. For example GET , POST , PUT etc. (default: GET ) |
url |
str | URL to use with the request. |
body |
bytes | Body to send with the request. |
headers |
list | Headers to send with the request. Must be a list with [[Key, Value],..] tuples. |
params |
list | URL Params to send with the request. Must be a list with [[Key, Value],..] tuples. |