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 ElysiaRun to see the response
Request body
{"name":"Ada"}Response
Run to see the response
How it works
Section titled “How it works”.getand.postregister routes; a handler returns a string, an object (sent as JSON) or aResponse.paramsare typed from the path, soidis 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 ofBun.serve.
Run it locally
Section titled “Run it locally”Install Elysia in a new folder and run the file with Bun:
bun add elysiabun index.tscurl -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.