Skip to content

At glance

Elysia is an ergonomic web framework for building backend servers with Bun.

Designed with simplicity and type safety in mind with familiar API with extensive support for TypeScript, optimized for Bun.

Here's a simple hello world in Elysia.

typescript
import { 
Elysia
} from 'elysia'
new
Elysia
()
.
get
('/', () => 'Hello Elysia')
.
get
('/user/:id', ({
params
: {
id
} }) =>
id
)
.
post
('/form', ({
body
}) =>
body
)
.
listen
(3000)

Navigate to localhost:3000 and it should show 'Hello Elysia' as a result.

localhost

GET

TIP

Hover over the code snippet to see the type definition.

In the mock browser, click on path highlight in blue to change path to preview a response and

Elysia can runs on browser and the result you see are actually run using Elysia.

Performance

Building on Bun and extensive optimization like Static Code Analysis allows Elysia to generate optimized code on the fly.

Elysia can outperform most of the web frameworks available today[1], and even match the performance of Golang and Rust framework[2].

FrameworkRuntimeAveragePlain TextDynamic ParametersJSON Body
bunbun262,660.433326,375.76237,083.18224,522.36
elysiabun255,574.717313,073.64241,891.57211,758.94
hyper-expressnode234,395.837311,775.43249,675141,737.08
honobun203,937.883239,229.82201,663.43170,920.4
h3node96,515.027114,971.8787,935.9486,637.27
oakdeno46,569.85355,174.2448,260.3636,274.96
fastifybun65,897.04392,856.7181,604.6623,229.76
fastifynode60,322.41371,150.5762,060.2647,756.41
koanode39,594.1446,219.6440,961.7231,601.06
expressbun29,715.53739,455.4634,700.8514,990.3
expressnode15,913.15317,736.9217,128.712,873.84

TypeScript

Elysia is designed to help you write less TypeScript.

Elysia's Type System is fine-tuned to infer your code into type automatically without needing to write explicit TypeScript while providing type-safety for both runtime and compile time to provide you with the most ergonomic developer experience.

Take a look at this example:

typescript
import { 
Elysia
} from 'elysia'
new
Elysia
()
.
get
('/user/:id', ({
params
: {
id
} }) =>
id
)
.
listen
(3000)

The above code create a path parameter "id", the value that replace :id will be passed to params.id both in runtime and type without manual type declaration.

localhost

GET

123

Elysia's goal is to help you write less TypeScript and focus more on Business logic. Let the complex type be handled by the framework.

TypeScript is not needed to use Elysia, but it's recommended to use Elysia with TypeScript.

Type Integrity

To take a step further, Elysia provide Elysia.t, a schema builder to validate type and value in both runtime and compile-time to create a single source of truth for your data-type.

Let's modify the previous code to accept only a numeric value instead of a string.

typescript
import { 
Elysia
,
t
} from 'elysia'
new
Elysia
()
.
get
('/user/:id', ({
params
: {
id
} }) =>
id
, {
params
:
t
.
Object
({
id
:
t
.
Numeric
(),
}), }) .
listen
(3000)

This code ensures that our path parameter id, will always be a numeric string and then transform to a number automatically in both runtime and compile-time (type-level).

TIP

Hover over "id" in the above code snippet to see a type definition.

With Elysia schema builder, we can ensure type safety like a strong-typed language with a single source of truth.

Standard

Elysia adopts many standards by default, like OpenAPI, and WinterCG compliance, allowing you to integrate with most of the industry standard tools or at least easily integrate with tools you are familiar with.

For instance, as Elysia adopts OpenAPI by default, generating a documentation with Swagger is as easy as adding a one-liner:

typescript
import { 
Elysia
,
t
} from 'elysia'
import {
swagger
} from '@elysiajs/swagger'
new
Elysia
()
.
use
(
swagger
())
.
get
('/user/:id', ({
params
: {
id
} }) =>
id
, {
params
:
t
.
Object
({
id
:
t
.
Numeric
(),
}), }) .
listen
(3000)

With the Swagger plugin, you can seamlessly generate a Swagger page without additional code or specific config and share it with your team effortlessly.

End-to-end Type Safety

With Elysia, type safety is not only limited to server-side only.

With Elysia, you can synchronize your type with your frontend team automatically like tRPC, with Elysia's client library, "Eden".

typescript
import { 
Elysia
,
t
} from 'elysia'
import {
swagger
} from '@elysiajs/swagger'
const
app
= new
Elysia
()
.
use
(
swagger
())
.
get
('/user/:id', ({
params
: {
id
} }) =>
id
, {
params
:
t
.
Object
({
id
:
t
.
Numeric
(),
}), }) .
listen
(3000)
export type
App
= typeof
app

And on your client-side:

typescript
// client.ts
import { 
treaty
} from '@elysiajs/eden'
import type {
App
} from './server'
const
app
=
treaty
<
App
>('localhost:3000')
// Get data from /user/617 const {
data
} = await
app
.
user
({
id
: 617 }).
get
()
console
.
log
(
data
)

With Eden, you can use the existing Elysia type to query Elysia server without code generation and synchronize type for both frontend and backend automatically.

Elysia is not only about helping you to create a confident backend but for all that is beautiful in this world.

Platform Agnostic

Elysia was designed but was not limited to Bun. Being WinterCG compliant allows you to deploy the Elysia server on Cloudflare Worker, Vercel Edge Function, and most other runtimes that support Web Standard Request.

Our Community

If you have questions or get stuck about Elysia, feel free to ask our community on GitHub Discussions, Discord, and Twitter.


1. Measure in requests/second. The benchmark for parsing query, path parameter and set response header on Debian 11, Intel i7-13700K tested on Bun 0.7.2 on 6 Aug 2023. See the benchmark condition here.

2. Based on TechEmpower Benchmark round 22.