HTTP
Perform HTTP requests to load and update data remotely and interact with external APIs
Types
HttpOptions
Options for an HTTP request
Property | Type | Description |
---|---|---|
url | string | URL to send the request to |
method | string | HTTP request method (“GET” / “POST” / “PUT” …etc) |
responseFormat | ”json” / “text” | Response type to get back (“json” for parsed JSON, “text” for plain text) |
headers | Record<string, string> | Map of header key value pairs |
body | object / string | Body of the HTTP request (Provide an object and it will be serialized as JSON) |
timeout | number | Timeout in seconds for the request |
HttpResponse
Options for an HTTP request
Property | Type | Description |
---|---|---|
status | number | HTTP response status code (i.e 200) |
headers | Record<string, string> | Map of header key value pairs on the response |
body | object / string | JSON object if “responseFormat” is “json” otherwise a string for “text” |
ok | boolean | true if the response status code is 2xx |
Functions
get
Function (url: string, options?: HttpOptions) => Promise<HttpResponse>
Performs an HTTP GET request to the provided URL returns a HttpResponse
Argument | Type | Example | Description |
---|---|---|---|
url | string | ”https://jsonplaceholder.typicode.com/todos/1” | URL for the HTTP request |
options | HttpOptions | Additional request options |
post
Function (url: string, body?: string | object, options?: HttpOptions) => Promise<HttpResponse>
Performs an HTTP POST request to the provided URL returns a HttpResponse
Argument | Type | Example | Description |
---|---|---|---|
url | string | ”https://jsonplaceholder.typicode.com/todos” | URL for the HTTP request |
body | string / object | Optional request body, objects will be serialized as JSON | |
options | HttpOptions | Additional request options |
put
Function (url: string, body?: string | object, options?: HttpOptions) => Promise<HttpResponse>
Performs an HTTP PUT request to the provided URL returns a HttpResponse
Argument | Type | Example | Description |
---|---|---|---|
url | string | ”https://jsonplaceholder.typicode.com/todos” | URL for the HTTP request |
body | string / object | Optional request body, objects will be serialized as JSON | |
options | HttpOptions | Additional request options |
patch
Function (url: string, body?: string | object, options?: HttpOptions) => Promise<HttpResponse>
Performs an HTTP PATCH request to the provided URL returns a HttpResponse
Argument | Type | Example | Description |
---|---|---|---|
url | string | ”https://jsonplaceholder.typicode.com/todos” | URL for the HTTP request |
body | string / object | Optional request body, objects will be serialized as JSON | |
options | HttpOptions | Additional request options |
request
Function (url: string, body?: string | object, options?: HttpOptions) => Promise<HttpResponse>
Performs an HTTP request returns a HttpResponse.
Use this if you are needing to use an HTTP method like “DELETE” which there is not a builtin function for.
Argument | Type | Example | Description |
---|---|---|---|
options | HttpOptions | Additional request options |