How it works

The Fetch API provides an interface for fetching resources from Azion’s global network, such as external resources across the network.

Fetch provides a generic definition of Request and Response objects. It allows them to handle or modify requests and responses or any kind of use case that may require you to generate your responses programmatically.

It also defines related concepts like CORS and the HTTP Origin header semantics, supplanting its separate definitions elsewhere.

Inside an Azion function, fetch() is how you reach out to other systems while handling a request: you can call an origin server, query a third-party API, or retrieve assets, all from a location close to the end user. The call returns a promise that resolves to a Response, which you can read, modify, or pass straight back through event.respondWith(). Because the request originates on Azion’s distributed architecture, these outbound calls benefit from Azion’s network and can be combined with caching and header manipulation to optimize delivery.

Constructor

fetch() Promise<response>

Properties

request: request string - the request object or string that represents the URL to fetch.

init: requestInit - the content of the request.

Example

addEventListener("fetch", event => {
return event.respondWith(
fetch("https://example.com")
)
})

Use cases

  • Forwarding a request to an origin server and returning the response to the client.
  • Calling external REST or GraphQL APIs to enrich or assemble a response on Azion’s global network.
  • Aggregating data from multiple backends within a single function before responding.
  • Retrieving remote assets or configuration and rewriting them before delivery.

For more information on Fetch API visit MDN Web Docs.