FetchEvent
The event type for fetch events dispatched to a Fastly Compute service.
Contains information about the incoming request, the downstream client, and the server. Use respondWith to send a response back to the client.
Properties
Information about the downstream client that made the request.
Information about the server which received the request.
The downstream request that came from the client
Methods
respondWith
View sourceSend a response back to the client.
Note: The service will be kept alive until the response has been fully sent.
If the response contains a streaming body created by the service itself, then the service will be kept alive until the body ReadableStream has been closed or errored.
However, if the body is a stream originating in a request to a backend, i.e. if a backend response's Response.body is passed as input to the Response constructor, the service will not be kept alive until sending the body has finished.
Note: If response is a Promise, the service will be kept alive until the
response has been resolved or rejected, and the Response it resolved to has been
fully sent.
Note: Use FetchEvent.waitUntil to extend the service's lifetime further if necessary.
Parameters
- response: Response | PromiseLike<Response>
- Response to send back down to the client
Returns
sendEarlyHints
View sourceSend a 103 Early Hints response back to the client.
Must be called before respondWith.
Parameters
- headers: HeadersInit
Headers to send back down to the client.
Returns
event.sendEarlyHints({ link: "</style.css>; rel=preload; as=style" });
event.sendEarlyHints([ ["link", "</style.css>; rel=preload; as=style"], ["link", "</script.js>; rel=preload; as=script"],]);waitUntil
View sourceExtend the service's lifetime to ensure asynchronous operations succeed.
By default, a service will shut down as soon as the response passed to
respondWith has been sent. waitUntil can be used to
ensure that the service will stay alive until additional asynchronous operations have
completed, such as sending telemetry data to a separate backend after the response has
been sent.
Must be initially called synchronously within the event callback, but after that it can be called multiple times.
Parameters
- promise: Promise<any>
The
Promiseto wait for.
Returns