---
title: FetchEvent
summary: The event type for fetch events dispatched to a Fastly Compute service.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.FetchEvent/
---

**Kind:** Interface  
**Module:** [globals](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/)  
**Package:** @fastly/js-compute 4.0.1  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L301

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](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.FetchEvent/#method-respondWith) to send a
response back to the client.

## Properties

### client

**Type:** `ClientInfo`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L305

Information about the downstream client that made the request.

### server

**Type:** `ServerInfo`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L310

Information about the server which received the request.

### request

**Type:** `Request`  
**Flags:** read-only  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L314

The downstream request that came from the client

## Methods

### respondWith

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L337

```javascript
respondWith(response: Response | PromiseLike<Response>): void
```

Send 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](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.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](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.Response/) is passed as input to the [Response](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.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](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.Response/) it resolved to has been
fully sent.

**Note**: Use [FetchEvent.waitUntil](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.FetchEvent/#method-waitUntil) to extend the service's lifetime further if
necessary.

**Parameters**

- `response`: `Response | PromiseLike<Response>` — - Response to send back down to the client

**Returns**

`void`

### sendEarlyHints

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L358

```javascript
sendEarlyHints(headers: HeadersInit): void
```

Send a [103 Early Hints](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/103)
response back to the client.

Must be called before [respondWith](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.FetchEvent/#method-respondWith).

**Parameters**

- `headers`: `HeadersInit` — Headers to send back down to the client.

**Returns**

`void`

```js
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

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/globals.d.ts#L374

```javascript
waitUntil(promise: Promise<any>): void
```

Extend the service's lifetime to ensure asynchronous operations succeed.

By default, a service will shut down as soon as the response passed to
[respondWith](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.FetchEvent/#method-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 `Promise` to wait for.

**Returns**

`void`
