REST

Send REST requests with the REST built-in.
Airplane's REST SDK makes it easy to issue one-off REST requests from a task. To use this SDK, you'll need to configure a REST resource.

Request

Perform a request against a REST resource.
typescript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "update_user_profile",
6
name: "Update user profile",
7
resources: ["profile_api"],
8
},
9
async () => {
10
const run = await airplane.rest.request<{ userId: string; avatar: string }>(
11
// Slug of the REST resource to query
12
"profile_api",
13
// REST method to execute
14
"POST",
15
// URL path
16
"/profile",
17
// Options
18
{
19
// Request body
20
body: {
21
name: "Bob",
22
job: "Engineer",
23
},
24
// Body type
25
bodyType: "json",
26
},
27
);
28
return run.output.response;
29
},
30
);
airplane.rest.request(restResource, method, path, opts)
restResource
REQUIRED
string

Slug of REST resource to use. See Resources.

method
REQUIRED
"GET" | "POST" | "PUT" | "PATCH" | "DELETE"

The REST API method.

path
optional
Default
""
string

Optional path to append to the base URL configured in the REST resource.

opts.body
Default
null
object

Optional request body.

opts.bodyType
Default
""
"json" | "raw" | "form-data" | "x-www-form-urlencoded"

Optional body content type.

opts.headers
Default
null
object

Optional object containing request headers.

opts.formData
Default
null
object

Optional form data.

opts.urlParams
Default
null
object

Optional object containing URL parameters.

opts.retryFailures
Default
false
boolean

True to retry the request on 500, 502, 503, and 504 error codes. Requests will always be retried on 408 and 429 error codes.

Returns
response
string | object

The return value from the rest call.