REST APIs
Call a REST API from a function with fetch, using the GET, DELETE, POST, PUT, and PATCH methods with JSON data.
Make outbound HTTP requests from a function using the fetch API, covering the GET, DELETE, POST, PUT, and PATCH methods with JSON data. Use these snippets when your function needs to call a REST API, whether to read data, submit a form, or update a resource, while running close to the user on Azion’s global network.
Examples
Get
Delete
Post
Put
Patch
How it works
Each example calls fetch() with a URL and an options object whose method field selects the HTTP verb. Request metadata such as authorization tokens and the Content-Type are passed through headers, either as a Headers instance or a plain object, while bodies are sent as FormData or as a JSON string produced by JSON.stringify. The returned promise resolves to a Response, which the snippets read with .then(response => response.json()) or .text() to consume the payload, and .catch() handles any network or parsing error. Running these requests on a distributed architecture keeps the calling logic close to the user.