Choosing the right framework can make all the difference in building efficient, scalable APIs. ElysiaJS, a lightweight Node.js framework, pairs exceptionally well with Bun's high-performance runtime and OpenAPI's standardization for documentation and client generation. This combination offers developers a streamlined path to creating robust RESTful services with minimal overhead. As APIs become the backbone of modern applications, getting started with ElysiaJS, OpenAPI, and Bun equips you to deliver type-safe, well-documented endpoints quickly. In this guide, we'll cover everything from the fundamentals of ElysiaJS to hands-on setup, installation steps across platforms, and practical code examples. This tutorial will help you integrate elysiajs with openapi seamlessly, leveraging Bun's speed for an optimal development experience.
Want an integrated, All-in-One platform for your Developer Team to work together with maximum productivity?
Apidog delivers all your demands, and replaces Postman at a much more affordable price!
What is ElysiaJS?
ElysiaJS is a lightweight, fast Node.js web framework designed to be minimal yet highly extensible for building RESTful APIs. It emphasizes a small surface area, clean TypeScript support, and an intuitive API for defining routes, middleware, and plugins. ElysiaJS aims to deliver performance with a developer-friendly experience and strong OpenAPI integration out of the box. Its core strengths include first-class OpenAPI support, a plugin ecosystem, and a design that favors speed and simplicity without locking you into heavy abstractions. This makes ElysiaJS particularly appealing for developers who want to focus on logic rather than boilerplate, while ensuring their APIs are easy to document and consume through OpenAPI specifications.
Why Choose ElysiaJS in 2025?
Selecting ElysiaJS brings several compelling benefits that enhance your API development process.
- Performance stands out with its lean runtime and focus on fast route handling and low overhead, allowing applications to scale efficiently under load. The built-in OpenAPI readiness means you can generate and serve OpenAPI specs effortlessly, which simplifies API documentation and client generation—crucial for teams collaborating on microservices or public APIs.
- Developer experience is another highlight: ElysiaJS is TypeScript-friendly, with concise route definitions and a modular architecture that supports growth as your project expands. Its ecosystem includes a growing set of plugins for OpenAPI support, documentation, and testing utilities, integrating smoothly with existing tools. The OpenAPI-first design ensures consistency between your code and docs, reducing maintenance efforts.

What is Bun?
Bun is a fast JavaScript runtime, package manager, and bundler all-in-one. It’s designed to be a drop-in replacement for Node.js in many cases, offering faster startup times and efficient tooling. Bun can speed up development workflows, dependency installation, and script execution, making it a popular pairing with modern frameworks like ElysiaJS. By handling multiple roles in the JavaScript ecosystem, Bun reduces context-switching, allowing developers to focus on building rather than managing tools. Its compatibility with Node APIs ensures a smooth transition, while native TypeScript and JSX support enhances productivity in ElysiaJS projects.

Installing Bun (MacOS, Linux, and Windows)
Getting Bun up and running is straightforward across platforms, ensuring you can pair it with ElysiaJS quickly.
- For MacOS, open Terminal and run the installation script:
curl -fsSL https://bun.sh/install | bash. This downloads and sets up Bun, adding it to your PATH. Verify withbun --version. - On Linux, use the same curl command in your terminal:
curl -fsSL https://bun.sh/install | bash. It supports major distributions like Ubuntu and Fedora. Restart your shell or source your profile, then checkbun --versionto confirm. - Windows users can install via PowerShell as administrator:
powershell -c "irm bun.sh/install.ps1 | iex". This handles the setup, including Chocolatey integration if needed. Launch PowerShell again and runbun --versionto verify.

In all cases, Bun installs in seconds and is ready for ElysiaJS projects—no additional configuration required for basic use.
Getting Started with ElysiaJS
Embarking on an ElysiaJS project starts with a few prerequisites:
- A Node.js environment or Bun installed (If opting for Bun's faster tooling, download it from bun.sh as outlined earlier).
- A project directory.
To initialize, use Bun for speed: bun create elysia my-api. This scaffolds a basic structure with package.json and TypeScript support.

Without Bun, run npm create elysia my-api via npm. Navigate into the folder with cd my-api, and you're set to define routes.
ElysiaJS's minimal setup encourages rapid prototyping—import the core module, define handlers, and listen on a port. This foundation scales easily, integrating OpenAPI for documentation from the outset.
Installing and Setting Up ElysiaJS
Installation is a one-liner once your runtime is ready. With Bun: bun install elysia.

For npm: npm install elysia. If using TypeScript, add @types/node for completeness.
Setup involves creating an entry file, index.ts:
import { Elysia } from "elysia";
const app = new Elysia().get("/", () => "Hello Elysia").listen(3000);
console.log(
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);Run with Bun: bun run index.ts, or Node: npx ts-node index.ts. Visit "http://localhost:3000" to see the response. This basic app confirms ElysiaJS's simplicity—extend it with middleware or plugins as needed.

Integrating ElysiaJS with OpenAPI
ElysiaJS's OpenAPI support shines through plugins, enabling auto-generated specs from your routes. Install the plugin: bun add @elysiajs/openapi (or npm equivalent).

Configure in your app:
import { Elysia } from 'elysia'
import { openapi, fromTypes } from '@elysiajs/openapi'
export const app = new Elysia()
.use(
openapi({
references: fromTypes()
})
)
.get(
'/pets',
() => [
{ id: 1, name: 'Fluffy' },
{ id: 2, name: 'Spot' }
],
({
summary: 'Get all pets',
responses: { 200: { description: 'Success' } }
} as any)
)
.listen(3000)
Access docs at "/openapi" or "/docs" (i.e. "http://localhost:3000/openapi"), where Swagger UI renders interactive schemas. ElysiaJS infers types from handlers, tightening code-spec alignment. For advanced setups, generate from TypeScript using ecosystem tools, ensuring elysiajs with openapi evolves with your codebase.

Click "Test Request" to test the sample "Pets" API endpoint that we have just created.

Sample Code: Building and Testing a Basic ElysiaJS App
Testing ElysiaJS starts with a simple app. Expand the hello world:
import { Elysia } from 'elysia'
const app = new Elysia()
.get('/', () => 'Hello from ElysiaJS!')
.post('/echo', ({ body }) => body, {
body: t.Object({ message: t.String() })
})
.listen(3000, () => console.log('Server listening on http://localhost:3000'))
Run and test with curl: curl -X POST http://localhost:3000/echo -H "Content-Type: application/json" -d "{\"message\": \"Test\"}". Expect the echoed response.

For unit tests use bun:test. Create a folder "test" in your projects root directory and add a file index.test.ts with the following code:
import { describe, expect, it } from 'bun:test'
import { Elysia } from 'elysia'
describe('Elysia', () => {
it('returns a response', async () => {
const app = new Elysia().get('/', () => 'hi')
const response = await app
.handle(new Request('http://localhost/'))
.then((res) => res.text())
expect(response).toBe('hi')
})
})To run tests simply use the command: bun test.

This validates core functionality, confirming ElysiaJS's reliability.
Sample Code: ElysiaJS with OpenAPI in Action
For elysiajs with openapi, build a pet API:
import { Elysia, t } from 'elysia'
import { openapi, fromTypes } from '@elysiajs/openapi'
const app = new Elysia()
.use(
openapi({
references: fromTypes()
})
)
.get('/pets', () => [
{ id: 1, name: 'Fluffy', type: 'Cat' },
{ id: 2, name: 'Spot' }
], ({
summary: 'List pets',
responses: {
200: {
description: 'Success',
content: {
'application/json': {
schema: {
type: 'array',
items: { type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' }, type: { type: 'string' } } }
}
}
}
}
}
} as any))
.post('/pets', ({ body }) => ({ id: Date.now(), ...body }), {
body: t.Object({ name: t.String(), type: t.String() }),
summary: 'Create pet',
responses: { 200: { description: 'Created' } }
})
.listen(3000, () => console.log('Server listening on http://localhost:3000'))
import { Elysia, t } from 'elysia'
import { openapi, fromTypes } from '@elysiajs/openapi'
const app = new Elysia()
.use(
openapi({
references: fromTypes()
})
)
.get('/pets', () => [
{ id: 1, name: 'Fluffy', type: 'Cat' },
{ id: 2, name: 'Spot' }
], ({
summary: 'List pets',
responses: {
200: {
description: 'Success',
content: {
'application/json': {
schema: {
type: 'array',
items: { type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' }, type: { type: 'string' } } }
}
}
}
}
}
} as any))
.post('/pets', ({ body }) => ({ id: Date.now(), ...body }), {
body: t.Object({ name: t.String(), type: t.String() }),
summary: 'Create pet',
responses: { 200: { description: 'Created' } }
})
.listen(3000, () => console.log('Server listening on http://localhost:3000'))
Test the POST: curl -X POST http://localhost:3000/pets -H "Content-Type: application/json" -d '{"name": "Scooby Doo", "type": "Dog"}'. Visit /openapi for Swagger docs, verifying schemas and paths.

Practical Tips for Production Readiness
Type safety is paramount: Leverage TypeScript types for request bodies, responses, and route parameters to improve reliability and OpenAPI generation accuracy. Observability calls for adding logging, metrics, and error handling middleware to monitor API behavior. Security measures include implementing CORS controls, input validation, rate limiting, and authentication as needed. Packaging involves using Bun’s or your bundler’s production build steps to produce a lean deployment package. Documentation requires keeping the OpenAPI spec in sync with code to ensure client SDKs and documentation stay current.
Frequently Asked Questions
Q1: Is ElysiaJS suitable for large-scale applications?
Ans: Yes, its modular design and performance focus make it scalable for enterprise APIs.
Q2: Does ElysiaJS require TypeScript?
Ans: No, but it's highly recommended for type-safe OpenAPI generation.
Q3: How does Bun compare to Node.js with ElysiaJS?
Ans: Bun offers faster installs and runs, but Node.js works if you prefer familiarity.
Q4: Can I generate OpenAPI specs from existing code?
Ans: Absolutely, using ElysiaJS plugins that infer from route definitions.
Q5: What testing frameworks pair best with ElysiaJS?
Ans: Apidog, Vitest or Jest for unit tests, with Supertest for API simulations.


Conclusion: Build Smarter APIs with ElysiaJS, OpenAPI, and Bun
ElysiaJS, with its blend of speed and simplicity, paired with Bun's runtime efficiency and OpenAPI's documentation power, forms a compelling stack for API development. From installation to testing, this guide has equipped you to start building. Experiment with the samples, refine your routes, and watch your projects thrive—ElysiaJS is ready to power your next creation.




