Skip to main content

Default Routes

RapidREST ships seven ready-made route classes for common operational concerns: admin actions, Prometheus metrics, OpenAPI docs, service status, WebSocket push delivery, ACL management, and static file serving. These default route classes implement all of the behavior for its endpoints but are not automatically registered with the class loader and do not have a @Route decorator. This is intentional to ensure you have complete control over what endpoints the server exposes.

This means that in order to use a default route you must create an exported class in your project's src/ folder that extends one of these classes and adds the appropriate @Route or @ApiRoute decorator. Each default route class is prefixed with Base in the name (BaseAdminRoute, BaseMetricsRoute, BaseOpenAPIRoute, BaseStatusRoute, BasePushRoute, BaseACLRoute, BaseStaticRoute) so that you can easily name the final file as AdminRoute, MetricsRoute, and so on.

Class nameEndpoints it implementsDocs
BaseAdminRouteCache clearing, live log tail, release notes, restartAdmin
BaseMetricsRoutePrometheus metricsMetrics
BaseOpenAPIRouteSwagger UI, raw OpenAPI JSON/YAMLOpenAPI
BaseStatusRouteService status metadataStatus
BasePushRouteWebSocket push notification deliveryPush
BaseACLRoute<T>CRUD management of Access Control List recordsACL
BaseStaticRouteStatic file serving from the filesystemStatic Files

The CLI scaffold wires these up for you

When using the rapidrest generate server CLI command, you are prompted which default routes you would like to enable. If selected, a thin subclass for each base class (BaseAdminRoute, BaseMetricsRoute, BaseOpenAPIRoute, BaseStatusRoute, and BasePushRoute) is created under src/routes/, e.g.:

src/routes/StatusRoute.ts
import { BaseStatusRoute, RouteDecorators } from "@rapidrest/service-core";
const { Route } = RouteDecorators;

@Route("/status")
export class StatusRoute extends BaseStatusRoute {}

If you have an existing project that you would like to add these default routes to, you can use the rapidrest generate default-route --type <name> command, which also covers BaseStaticRoute (--type static) — see CLI Reference → Add-ons.

Because these files are ordinary auto-discovered route classes, they behave exactly like any other route in your project. Nothing distinguishes them at runtime as "built-in." You can delete the file to remove the endpoint entirely, change the @Route base path, or add further decorators (@Auth, @Protect, additional trusted_roles) directly on the subclass to lock it down further.

ACLRoute (extending BaseACLRoute) is also scaffolded, but only for projects with a database selected. Like AuthRoute and UserRoute, it needs somewhere to persist to. Which AccessControlList model it extends depends on the database you picked: AccessControlListMongo for MongoDB projects, AccessControlListSQL for PostgreSQL/SQLite ones. See ACL for details.

Using them without the CLI scaffold

If you're wiring service-core into a project by hand, or you deleted one of the generated files and want it back, the pattern is the same for every base route: extend it, apply @Route() with whatever base path you want, and export the class from anywhere under your source tree.

import { BaseMetricsRoute, RouteDecorators } from "@rapidrest/service-core";
const { Route } = RouteDecorators;

@Route("/metrics")
export class MetricsRoute extends BaseMetricsRoute {}