Group

Suppose you have many paths with the same prefix.

  • /user/sign-in
  • /user/sign-up
  • /user/profile

Instead of writing many same prefixes, you can group them.


Grouping allows you to combine multiple prefixes into one.

app.group("/user", app => app.post("/sign-in", signIn).post("/sign-up", signUp).post("/profile", getProfile));

You can create as many nested groups as you like:

app.group("/v1", app =>
  app
    .get("/", () => "Using v1")
    .group("/user", app => app.post("/sign-in", signIn).post("/sign-up", signUp).post("/profile", getProfile))
);

Plugin group

You can separate group into an instance and register the group as plugin for code separation and reduce nesting.

import { Elysia } from "elysia";

const users = new Elysia({ prefix: "/user" })
  .post("/sign-in", signIn)
  .post("/sign-up", signUp)
  .post("/profile", getProfile);

app.group("/v1", app => app.get("/", () => "Using v1").use(users));
ON THIS PAGE