JavaScript Runtime APIs ⁠-⁠ FetchEvent

FetchEvent is the event that passes the request through the addEventListener function. The addEventListener, in turn, defines the trigger for executing the JavaScript code and receives the request data.

addEventListener(type, listener)

event.type: fetch

event.request: request - the HTTP request received by the Edge Function.

When the Edge Function receives a request, the Runtime executes the FetchEvent, which can be manipulated by the eventListener of a fetch type that, in turn, can call the method that defines what will happen until the response:

event.respondWith(response Request|Promise) // the HTTP request received by the Edge Function.
addEventListener("fetch", event => {
event.respondWith(handleRequest(event))
})

For more information on fetchEvent visit MDN Web Docs.


Contributors