Skip to content
Run BunYour friendly Bun playground

Elysia playground: run an Elysia app in your browser

Elysia is a web framework built for Bun. This example installs it from npm and serves a small API. Press Run: the install and the server both happen in your browser.

import { Elysia, t } from "elysia";

new Elysia()
  .get("/", () => "Hello Elysia")
  .get("/user/:id", ({ params: { id } }) => ({ id, name: `User ${id}` }))
  .post("/user", ({ body }) => ({ created: body.name }), {
    body: t.Object({ name: t.String() }),
  })
  .listen(3000);
Hello Elysia

Run to see the response

Request body
{"name":"Ada"}
Response

Run to see the response

  • .get and .post register routes; a handler returns a string, an object (sent as JSON) or a Response.
  • params are typed from the path, so id is known to be a string without a cast.
  • t.Object(...) validates the request body: post {} instead and Elysia answers with a 422 explaining what’s missing.
  • .listen(3000) starts the server on top of Bun.serve.

Install Elysia in a new folder and run the file with Bun:

Terminal window
bun add elysia
bun index.ts
curl -X POST localhost:3000/user -H "Content-Type: application/json" -d '{"name":"Ada"}'

The playground has a bigger Elysia example, and one on the Elysia 2 release candidate with plugins, cookies, server-sent events and a WebSocket chat. Frameworks lists what else runs.

Was this page helpful?

Sends the rating and this page's address; nothing else unless you write it. Privacy

runbun is an independent project, not affiliated with or endorsed by Oven or Bun.