- Docs
- Products
- Edge Application
- Edge Functions
- Edge Functions - JavaScript Runtime APIs
- JavaScript Runtime APIs - FetchEvent
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 receive 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))
})
Didn’t find what you were looking for? Open a support ticket.