1 of 20
2 of 20
3 of 20
4 of 20
5 of 20
6 of 20
7 of 20
8 of 20
9 of 20
10 of 20
11 of 20
12 of 20
13 of 20
14 of 20
15 of 20
16 of 20
17 of 20
18 of 20
19 of 20
20 of 20

site

doc

blog

success stories

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.