Skip to content
Discussion options

You must be logged in to vote

@Serhioromano elysia's validation is statically bound at route registration time, so a wildcard route gets one schema for all paths. there's no built-in way to swap validators dynamically per request.

the idiomatic approach is to use .group() with explicit routes:

const app = new Elysia()
  .group('/api', (app) =>
    app
      .get('/user', ({ query }) => ({ id: query.id }), {
        query: t.Object({ id: t.String() })
      })
      .get('/login', ({ query }) => ({ name: query.name }), {
        query: t.Object({ name: t.String(), pass: t.String() })
      })
  )

if you have shared validation across all /api routes (e.g., auth headers), use .guard():

.group('/api', {
  headers: t.Object({

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Serhioromano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants