Skip to content

Framework Usage

ResourcesJS returns plain objects. Use your framework’s normal response API.

app.get("/users/:id", async (_request, response) => {
const user = await service.find();
response.json(UserResource.make(user));
});
fastify.get("/users/:id", async () => {
const user = await service.find();
return UserResource.make(user);
});
app.get("/users/:id", async (context) => {
const user = await service.find();
return context.json(UserResource.make(user));
});
@Controller("users")
export class UserController {
@Get(":id")
async show() {
const user = await this.service.find();
return UserResource.make(user);
}
}
new Elysia().get("/users/:id", async () => {
const user = await service.find();
return UserResource.make(user);
});

Elysia’s Node adapter expects a global Web Crypto implementation. Node 20 and newer provide it globally. On Node 18, initialize it from node:crypto before loading Elysia.

export default class UsersController {
async show() {
const user = await service.find();
return UserResource.make(user);
}
}

The package test suite verifies compatibility examples for Express 5, Fastify 4, Hono 4, NestJS 10, Elysia 1.4, and AdonisJS 6.2.x.