Your first Elysia app
Let’s build a simple REST API to learn the fundamentals of Elysia. We’ll create an API that manages a list of users with full type safety and validation.Make sure you’ve installed Elysia before continuing.
Basic server
Create a new file calledindex.ts and add the following code:
index.ts
http://localhost:3000 and you’ll see “Hello Elysia”!
Adding routes
Let’s add more routes to handle different HTTP methods:index.ts
Schema validation
Now let’s add type-safe validation using Elysia’s built-in schema system:index.ts
Building a REST API
Let’s build a complete REST API with in-memory storage:index.ts
Testing your API
State management
For more complex state, use Elysia’s state management:/count will increment the counter.
Route grouping and guards
Organize routes and apply shared validation with groups and guards:Error handling
Handle errors gracefully with error hooks:Lifecycle hooks
Add middleware logic with lifecycle hooks:Next steps
Now that you’ve built your first Elysia application, explore these topics:Routing
Learn advanced routing patterns and dynamic routes.
Validation
Deep dive into schema validation and type safety.
Plugins
Extend your app with the plugin ecosystem.
State & decorators
Manage state and add custom functionality.
Guards & groups
Organize routes and apply shared logic.
Error handling
Handle errors and validation failures.