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.3.
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. |
| req | Make a HTTP 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));
});Syntax: req(url, options)
A valid method is required.
url: The URL for the request.options: Thing with properties for the request. At least amethodis required.
| Option | Type | Description |
|---|---|---|
method |
str | Method to use. For example GET, POST, PUT, PATCH or DELETE. |
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. |
allow_redirects |
bool | If true, 10 redirects are allowed. |
params |
list | URL Params to send with the request. Must be a list with [[Key, Value],..] tuples. |