DEV Community

Cover image for Declarative Routing: Groups and Resources in a Few Lines
zintrust Zin
zintrust Zin

Posted on

Declarative Routing: Groups and Resources in a Few Lines

Most frameworks make you write the same route scaffolding for every resource: index, show, create, update, delete. ZinTrust's routing is declarative, so you can describe the shape of your API and skip the repetition.

Create a router, register routes, and group them:

  • Router.createRouter() creates a router.
  • Router.get, Router.post, Router.put, Router.patch, and Router.del register routes.
  • Router.group() groups routes that share a prefix or middleware.
  • Router.resource() generates the standard CRUD routes for a resource.

Per-route middleware is declared as metadata, like { middleware: ['auth'] }, so the protection is visible right where the route is defined.

Readable routes make code reviews faster, onboarding easier, and changes safer. Fewer lines to read means fewer places for mistakes to hide.

Try it: npm install -g @zintrust/core && zin new my-app

Top comments (0)