> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/oven-sh/bun/llms.txt
> Use this file to discover all available pages before exploring further.

# Elysia Framework

> Build a type-safe, high-performance HTTP server with Elysia, a framework designed specifically for Bun.

[Elysia](https://elysiajs.com) is a TypeScript web framework built for Bun. It takes full advantage of Bun's HTTP, file system, and hot reloading APIs, and is one of the [fastest Bun HTTP frameworks](https://github.com/SaltyAom/bun-http-framework-benchmark).

## Quick start

Scaffold a new Elysia project with `bun create`:

```bash theme={null}
bun create elysia my-app
cd my-app
bun run dev
```

## Manual setup

<Steps>
  <Step title="Install Elysia">
    ```bash theme={null}
    bun add elysia
    ```
  </Step>

  <Step title="Create a server">
    ```typescript src/index.ts theme={null}
    import { Elysia } from "elysia";

    const app = new Elysia()
      .get("/", () => "Hello Elysia")
      .listen(3000);

    console.log(`Running at http://localhost:${app.server?.port}`);
    ```
  </Step>

  <Step title="Run the server">
    ```bash theme={null}
    bun run src/index.ts
    ```
  </Step>
</Steps>

## Routing

Elysia uses a chainable API for defining routes:

```typescript theme={null}
import { Elysia } from "elysia";

const app = new Elysia()
  .get("/", () => "Hello!")
  .get("/users/:id", ({ params }) => `User: ${params.id}`)
  .post("/users", ({ body }) => body)
  .put("/users/:id", ({ params, body }) => ({ id: params.id, ...body }))
  .delete("/users/:id", ({ params }) => `Deleted ${params.id}`)
  .listen(3000);
```

## Schema validation

Elysia provides end-to-end type safety through its `t` schema validation module. Schemas are validated at runtime and inferred as TypeScript types automatically:

```typescript theme={null}
import { Elysia, t } from "elysia";

const app = new Elysia()
  .post("/sign-in", ({ body }) => body, {
    body: t.Object({
      username: t.String(),
      password: t.String({ minLength: 8 }),
    }),
  })
  .listen(3000);
```

If the request body does not match the schema, Elysia returns a `400 Bad Request` with a descriptive error.

## Middleware (lifecycle hooks)

Use Elysia's lifecycle hooks to run code before or after route handlers:

```typescript theme={null}
import { Elysia } from "elysia";

const app = new Elysia()
  .onRequest(({ request }) => {
    console.log(`${request.method} ${request.url}`);
  })
  .onError(({ code, error }) => {
    if (code === "NOT_FOUND") return new Response("Not found", { status: 404 });
  })
  .get("/", () => "OK")
  .listen(3000);
```

## Plugins

Elysia has a plugin system for sharing routes, middleware, and state across your app:

```typescript theme={null}
import { Elysia } from "elysia";

const auth = new Elysia({ name: "auth" })
  .derive({ as: "scoped" }, ({ headers }) => ({
    user: headers["x-user"] ?? "anonymous",
  }))
  .get("/me", ({ user }) => user);

const app = new Elysia()
  .use(auth)
  .get("/", () => "Hello!")
  .listen(3000);
```

Popular community plugins include:

* `@elysiajs/bearer` — Bearer token extraction
* `@elysiajs/cors` — CORS configuration
* `@elysiajs/jwt` — JWT authentication
* `@elysiajs/swagger` — OpenAPI / Swagger UI generation
* `@elysiajs/trpc` — tRPC adapter

Install any of them with `bun add`:

```bash theme={null}
bun add @elysiajs/cors @elysiajs/swagger
```

<Tip>
  See the [Elysia documentation](https://elysiajs.com/quick-start.html) for the complete API reference, including WebSocket support, file uploads, and server-sent events.
</Tip>
