Menu

Declarative Routing: Groups and Resources in a Few Lines
📰

Declarative Routing: Groups and Resources in a Few Lines

DEV Community: typescript·zintrust Zin·1 day ago
#xh3CZa3L
#devtotypescript#devto#dev#router#zintrust
Reading 0:00
15s threshold
Cover image for Declarative Routing: Groups and Resources in a Few Lines

zintrust Zin

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