# Respond with another site

Answer an incoming request with content fetched from a different website. Use this pattern for a temporary substitution, or to serve another site's response without issuing an HTTP redirect that changes the URL in the browser.

```js
  addEventListener("fetch", event => {
    return event.respondWith(
      fetch("https://www.azion.com/en/")
    )
  })
```

## How it works

The function listens for the `fetch` event with `addEventListener`. Instead of building a local `Response`, it calls `fetch()` to request a resource from another site and passes the resulting promise straight to `event.respondWith()`, which accepts a promise as well as a `Response`. The function waits for the upstream response and relays it back to the client as the answer to the original request.

The substitution happens inside the function, so the visitor's address bar keeps the original URL. The outbound `fetch()` counts against the sub-request limit for the invocation, and the upstream site's status and headers are the ones the client receives.

The relayed response can be kept rather than fetched again on the next request. The [Cache API](/en/documentation/devtools/runtime/api-reference/cache/) writes it with `cache.put(request, fetchResponse.clone())`, and handing that call to `ctx.waitUntil()` keeps the write off the response path.

## Related resources

- [JavaScript examples](/en/documentation/platform/functions/javascript-examples.md): Browse the rest of the snippets in this collection.
- [FetchEvent](/en/documentation/devtools/runtime/api-reference/fetch-event.md): Read the reference for the event this handler listens to, including `respondWith()`.
- [Fetch API](/en/documentation/devtools/runtime/api-reference/fetch.md): Check what `fetch()` accepts and returns inside a function.
- [Functions limits](/en/documentation/platform/functions/limits.md): Review the sub-request limit and the other per-invocation limits.
- [How Functions works](/en/documentation/platform/functions/how-it-works.md#the-function-the-instance-and-the-rule): The instance and the rule this code needs before it receives traffic.
- [Response](/en/documentation/devtools/runtime/api-reference/response.md#constructor): Every parameter of the response object this function relays.
