---
title: createFanoutHandoff
summary: Creates a Response that instructs Fastly to pass the original request through Fanout to the declared backend.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/fanout/fn.createFanoutHandoff/
---

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

```javascript
createFanoutHandoff(request: Request, backend: string): Response
```

Creates a [Response](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.Response/) that instructs Fastly to pass the original
request through [Fanout](https://www.fastly.com/documentation/guides/concepts/real-time-messaging/fanout/)
to the declared backend.

**Note**: Can only be used when processing requests, not during build-time
initialization.

**Parameters**

- `request`: `Request` — The request to pass through Fanout.
- `backend`: `string`

  The name of the backend that Fanout should send the request
  to. The name must be between 1 and 254 characters inclusive.

**Returns**

`Response`

A [Response](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.Response/) that can be passed to `event.respondWith`.

**Throws**

- `Error` if `request` is not a [Request](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/globals/interface.Request/) instance, or
if `backend` is an empty string or longer than 254 characters.

```js
import { createFanoutHandoff } from "fastly:fanout";

async function handleRequest(event) {
  const url = new URL(event.request.url);
  if (url.pathname === "/stream") {
    return createFanoutHandoff(event.request, "my-backend");
  }
  return new Response("Not found", { status: 404 });
}

addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
```
