LogoHuk Relay Docs

Make HTTP Request

Functions can initiate HTTP requests to 3rd party services. This is useful for fetching additional data or triggering side effects.

Basic Usage

You can use the standard fetch API to make requests.

var res = fetch('https://api.example.com/data', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({ foo: 'bar' })
});

var data = res.json();
console.log(data);

Async/Await

Complete support for async/await allows cleaner code:

async function main() {
    try {
        const response = await fetch('https://httpbin.org/json');
        const json = await response.json();
        console.log(JSON.stringify(json));
    } catch (e) {
        console.error(e);
    }
}

main(); // Check if your environment requires invoking main or supports top-level await

Table of Contents