JavaScript Runtime APIs - Fetch API

How it works

The Fetch API provides an interface for fetching resources from the edge 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.

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")
)
})

For more information on Fetch API visit MDN Web Docs.


Contributors