Routing
GraceJS offers a powerful filesystem-based routing system that automatically maps your file structure to URL paths. This method is preferred for its simplicity and ease of management.
Filesystem-Based Routing
To use filesystem-based routing, your route files should follow a specific naming pattern that reflects the HTTP method and the route path. For instance, a file named /v1/users/me/get.ts
automatically registers a GET route at /v1/users/me
.
Here's an example route file, get.ts
:
Registering Routes
To register routes from a directory, use the registerRoutes
method of the Grace instance:
This method scans the specified directory and automatically registers all the routes.
Last updated