# Preview deployment

**Preview deployment** runs a [function](/en/documentation/platform/functions/) in Azion Console and shows the response the code returns. It calls `PreviewProvider`, an auxiliary function in the source code that builds a simulated request and passes it to the handler. The output appears in the code editor, so you read the response before the function serves traffic.

---

## PreviewProvider function

`PreviewProvider` is the entry point of a preview. It builds the request the preview sends, calls the function that processes that request, and returns the response the preview renders:

```javascript
function PreviewProvider(args) {
  var request = new Request("https://www.azion.com/example", {
    method: "GET",
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Bearer [TOKEN VALUE]"
    },
    redirect: "follow",
  });
  return handleRequest(request);
}
```

The handler reads the properties of that request, so the values set inside `PreviewProvider` decide which path through the function runs.

> **Note**
>
> Azion Console renders no preview while the source code carries no `PreviewProvider` function. The preview shows a warning that names the missing function.

---

## Request simulation

Change the values inside `PreviewProvider` to exercise a different path through the function. A handler that branches on the request method returns HTML for a `GET` and JSON for a `POST`:

```javascript
const html = '<h1>Hello World</h1>'
const data = { message: 'Hello World' }

async function handleRequest(request) {
  switch (request.method) {
    case 'GET':
      return new Response(html, {
        headers: {
          "content-type": "text/html",
        }
      })
    case 'POST':
      return new Response(JSON.stringify(data), {
        headers: {
          "content-type": "application/json",
        }
      })
  }
}
```

Each branch sets the `content-type` header for the format it returns. Switch the method inside `PreviewProvider` from `GET` to `POST` to read the other response.

---

## Response rendering

The preview renders a response by its `content-type` header:

| `content-type`     | Preview output                      |
| ------------------ | ----------------------------------- |
| `text/html`        | The HTML page, rendered.            |
| `application/json` | The JSON body the function returns. |

Azion Console shows the output in the code editor of the function. Select **Open** to show the same output in a separate browser tab. The `inspect` tool inside Preview deployment shows the behavior of the function in real time.

---

## Related resources

- [Functions quickstart](/en/documentation/platform/functions/quickstart.md): Create, instantiate, and run your first function end to end.
- [Code editor](/en/documentation/platform/functions/code-editor.md): Write the function whose response the preview renders.
- [Function instances](/en/documentation/platform/applications/functions-instances.md): Bind the function to an application once the response is the one you want.
- [Troubleshooting](/en/documentation/platform/functions/troubleshooting.md): Find the cause when a function fails or returns nothing.
- [Query usage data from Functions](/en/documentation/guides/platform/observability/query-functions-usage-data-with-graphql.md): Read back the compute time and the invocations an account has consumed.
