---
title: "Status"
description: "Learn how to manage status codes and headers in Elysia to control HTTP responses effectively."
url: "https://next.elysiajs.com/tutorial/getting-started/status-and-headers/"
---

# Status

A status code is an indicator of how the server handles the request.

You must have heard of the infamous **404 Not Found** when you visit a non-existing page.

That’s a **status code**.

By default, Elysia will return **200 OK** for a successful request.

Elysia also returns many other status codes depending on the situation like:

- 400 Bad Request
- 422 Unprocessable Entity
- 500 Internal Server Error

You can also return a status code by returning your response using the `status` function.

```typescript
import { Elysia } from 'elysia'

new Elysia()
  .get('/', ({ status }) => status(418, "I'm a teapot"))
  .listen(3000)
```

The status code can be a number or a string status name. These are equivalent:

```typescript
status(418, "I'm a teapot")
status("I'm a teapot", "I'm a teapot")
```

String status names provide TypeScript autocompletion for all valid HTTP statuses.

See [Status](/essential/handler/#status).

## Redirect

Similarly, you can also redirect the request to another URL by returning the `redirect` function.

```typescript
import { Elysia } from 'elysia'

new Elysia()
  .get('/', ({ redirect }) => redirect('https://next.elysiajs.com/'))
  .listen(3000)
```

See [Redirect](/essential/handler/#redirect).

## Headers

Unlike status code and redirect, which you can return directly, you might need to set headers multiple times in your application.

That’s why instead of returning a `headers` function, Elysia provides a `set.headers` object to set headers.

```typescript
import { Elysia } from 'elysia'

new Elysia()
  .get('/', ({ set }) => {
    set.headers['x-powered-by'] = 'Elysia'

    return 'Hello World'
  })
  .listen(3000)
```

Because `headers` represents **request headers**, Elysia distinguishes between request headers and response headers by prefixing **set.headers** for response.

See [Headers](/essential/handler/#setheaders).

## Assignment

Let’s exercise what we have learned.
