Http
util.http : object
HTTP requests and webhooks.
Kind: static namespace of util
- .http :
object- .webhook :
object- .geturl(sourcename) ⇒
Promise.<string> - .poll(sourcename) ⇒
Promise.<Array.<Object>> - .ack(webhookid)
- .geturl(sourcename) ⇒
- .post(url, data, [responseType], [headers], [method], [continueOnBadStatusCode], [timeoutSeconds]) ⇒
Promise.<(string|Blob|ArrayBuffer|Object)> - .fetch(url, [responseType], [timeoutSeconds]) ⇒
Promise.<(string|Blob|ArrayBuffer|Object)>
- .webhook :
http.webhook : object
Use webhooks via a PostalPoint cloud relay service.
Kind: static namespace of http
- .webhook :
object- .geturl(sourcename) ⇒
Promise.<string> - .poll(sourcename) ⇒
Promise.<Array.<Object>> - .ack(webhookid)
- .geturl(sourcename) ⇒
webhook.geturl(sourcename) ⇒ Promise.<string>
geturl - Returns a public URL that can be used as a webhook target/endpoint for third-party integrations.
Kind: static method of webhook
Returns: Promise.<string> - A URL for the webhook.
| Param | Type | Description |
|---|---|---|
| sourcename | string |
Unique identifier for the webhook |
webhook.poll(sourcename) ⇒ Promise.<Array.<Object>>
poll - Returns an array of webhook payloads received by the webhook identified by sourcename.
Kind: static method of webhook
Returns: Promise.<Array.<Object>> - Payloads as received by the webhook relay service.
| Param | Type | Description |
|---|---|---|
| sourcename | string |
Unique identifier for the webhook |
Example
[
{
// Unique ID. Used for ack(webhookid).
id: 123,
// UNIX timestamp (in seconds) of when the data was received by the webhook URL.
timestamp: 1234567890,
// Source name set in geturl()
source: "sourcename",
// JSON string of all the HTTP headers sent to the webhook URL.
headers: "{'Content-Type': 'application/json'}",
// Entire HTTP request body sent to the webhook URL.
body: ""
}
]
webhook.ack(webhookid)
ack - Acknowledge receipt of a webhook payload, deleting it from the relay server.
Kind: static method of webhook
| Param | Type | Description |
|---|---|---|
| webhookid | number |
Numeric unique ID received with the payload. See poll. |
http.post(url, data, [responseType], [headers], [method], [continueOnBadStatusCode], [timeoutSeconds]) ⇒ Promise.<(string|Blob|ArrayBuffer|Object)>
post - Fetch a HTTP POST request.
Kind: static method of http
Returns: Promise.<(string|Blob|ArrayBuffer|Object)> - The server response body. See responseType parameter.
| Param | Type | Default | Description |
|---|---|---|---|
| url | string |
||
| data | Object.<string, string> |
POST data key/value list | |
| [responseType] | string |
"text" |
"text", "blob", "buffer", or "json" |
| [headers] | Object.<string, string> |
HTTP headers to send. Defaults to {"Content-Type": "application/json"}. |
|
| [method] | string |
"POST" |
|
| [continueOnBadStatusCode] | boolean |
false |
If false, throws an Error when the HTTP response code is not 2XX. If true, ignores the response code and proceeds as normal. |
| [timeoutSeconds] | number |
15 |
Aborts the request (timeout) after this many seconds. |
http.fetch(url, [responseType], [timeoutSeconds]) ⇒ Promise.<(string|Blob|ArrayBuffer|Object)>
fetch - Fetch a HTTP GET request.
Kind: static method of http
Returns: Promise.<(string|Blob|ArrayBuffer|Object)> - The server response body. See responseType parameter.
| Param | Type | Default | Description |
|---|---|---|---|
| url | string |
||
| [responseType] | string |
"text" |
"text", "blob", "buffer", or "json" |
| [timeoutSeconds] | number |
15 |
Aborts the request (timeout) after this many seconds. |