Categorygithub.com/thingsdb/module-go-requests
modulepackage
0.1.2
Repository: https://github.com/thingsdb/module-go-requests.git
Documentation: pkg.go.dev

# README

Requests ThingsDB Module (Go)

Request module written using the Go language. This module can be used to make HTTP(S) requests with ThingsDB.

Installation

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.1.

Configuration

This module does not require any config.

Exposed functions

NameDescription
getMake a GET request.
postMake a POST request.
post_jsonMake a JSON POST request.
reqMake a HTTP request.

get

Syntax: get(url, options)

Arguments

  • url: The URL to make the GET request to.
  • options: Thing with properties to add to the GET request.

Example:

requests.get("https://reqbin.com/echo").then(|res| {
    res;  // just return the response.
});

post

Syntax: post(url, body, options)

Arguments

  • 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.

post_json

Syntax: post_json(url, body, options)

Like post, except that the headers will be set to accept and send JSON data.

Arguments

  • 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.

Example:

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));
});

req

Syntax: req(url, options)

A valid method is required.

Arguments

  • url: The URL for the request.
  • options: Thing with properties for the request. At least a method is required.

Properties

OptionTypeDescription
methodstrMethod to use. For example GET, POST, PUT, PATCH or DELETE.
urlstrURL to use with the request.
bodybytesBody to send with the request.
headerslistHeaders to send with the request. Must be a list with [[Key, Value],..] tuples.
paramslistURL Params to send with the request. Must be a list with [[Key, Value],..] tuples.