Make HTTP request
Making HTTP requests from Webhook Relay Functions

Functions can make multiple HTTP request calls to any external server. Some of the uses cases:
- Call 3rd party API to get additional authentication tokens before forwarding request.
- Send data to the external service directly, without relying on the webhook.
- Get additional data to the function so it can dynamically mutate the payload.
Using HTTP module
To make an HTTP request from a function:
// making HTTP call
const response = http.request("GET", "https://example.com")
// parsing response body from the API
const apiResponse = JSON.parse(response.body)
Specify request body
You can also make a POST, PUT, DELETE requests to a 3rd party APIs:
const payload = JSON.stringify({
action: "create_record",
user: "example",
})
const resp = http.request("POST", "http://example.com/api", { body: payload })
Reading response body
To read response body:
// making HTTP call
const response = http.request("GET", "https://example.com")
// received JSON string:
// {
// "firstname": "luke",
// "lastname": "skywalker"
// }
// parsing response body from the API
const apiResponse = JSON.parse(response.body)
// access values like 'apiResponse.firstname'
Query, headers, timeout
To specify query, timeout and headers:
// making HTTP call with options
const response = http.request("GET", "https://example.com", {
query: "page=1",
timeout: "5s",
headers: {
Accept: "*/*",
Authorization: "Basic 123456"
}
})
// parsing response body from the API
const apiResponse = JSON.parse(response.body)
HTTP module API reference
http.delete(url , options)
Attributes
| Name | Type | Description |
|---|---|---|
| url | String | URL of the resource to load |
| options | Table | Additional options |
Options
| Name | Type | Description |
|---|---|---|
| query | String | URL encoded query params |
| cookies | Table | Additional cookies to send with the request |
| headers | Table | Additional headers to send with the request |
Returns
http.response or (nil, error message)
http.get(url , options)
Attributes
| Name | Type | Description |
|---|---|---|
| url | String | URL of the resource to load |
| options | Table | Additional options |
Options
| Name | Type | Description |
|---|---|---|
| query | String | URL encoded query params |
| cookies | Table | Additional cookies to send with the request |
| headers | Table | Additional headers to send with the request |
Returns
http.response or (nil, error message)
http.head(url , options)
Attributes
| Name | Type | Description |
|---|---|---|
| url | String | URL of the resource to load |
| options | Table | Additional options |
Options
| Name | Type | Description |
|---|---|---|
| query | String | URL encoded query params |
| cookies | Table | Additional cookies to send with the request |
| headers | Table | Additional headers to send with the request |
Returns
http.response or (nil, error message)
http.patch(url , options)
Attributes
| Name | Type | Description |
|---|---|---|
| url | String | URL of the resource to load |
| options | Table | Additional options |
Options
| Name | Type | Description |
|---|---|---|
| query | String | URL encoded query params |
| cookies | Table | Additional cookies to send with the request |
| body | String | Request body. |
| form | String | Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded |
| headers | Table | Additional headers to send with the request |
Returns
http.response or (nil, error message)
http.post(url , options)
Attributes
| Name | Type | Description |
|---|---|---|
| url | String | URL of the resource to load |
| options | Table | Additional options |
Options
| Name | Type | Description |
|---|---|---|
| query | String | URL encoded query params |
| cookies | Table | Additional cookies to send with the request |
| body | String | Request body. |
| form | String | Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded |
| headers | Table | Additional headers to send with the request |
Returns
http.response or (nil, error message)
http.put(url , options)
Attributes
| Name | Type | Description |
|---|---|---|
| url | String | URL of the resource to load |
| options | Table | Additional options |
Options
| Name | Type | Description |
|---|---|---|
| query | String | URL encoded query params |
| cookies | Table | Additional cookies to send with the request |
| body | String | Request body. |
| form | String | Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded |
| headers | Table | Additional headers to send with the request |
Returns
http.response or (nil, error message)
http.request(method, url , options)
Attributes
| Name | Type | Description |
|---|---|---|
| method | String | The HTTP request method |
| url | String | URL of the resource to load |
| options | Table | Additional options |
Options
| Name | Type | Description |
|---|---|---|
| query | String | URL encoded query params |
| cookies | Table | Additional cookies to send with the request |
| body | String | Request body. |
| form | String | Deprecated. URL encoded request body. This will also set the Content-Type header to application/x-www-form-urlencoded |
| headers | Table | Additional headers to send with the request |
Returns
http.response or (nil, error message)
http.response
The http.response table contains information about a completed HTTP request.
Attributes
| Name | Type | Description |
|---|---|---|
| body | String | The HTTP response body |
| body_size | Number | The size of the HTTP reponse body in bytes |
| headers | Table | The HTTP response headers |
| cookies | Table | The cookies sent by the server in the HTTP response |
| status_code | Number | The HTTP response status code |
| url | String | The final URL the request ended pointing to after redirects |
