JavaScript Runtime APIs - FetchEvent
How it works
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.
Syntax
addEventListener(type, listener)
Properties
event.type: fetch
event.request: request
- the HTTP request received by the Edge Function.
Methods
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.
Example
addEventListener("fetch", event => { event.respondWith(handleRequest(event)) })
For more information on fetchEvent visit MDN Web Docs.
Contributors