Routing Conventions
1) Basic route
Section titled “1) Basic route”Use a normal file for a GET route.
routes/hello.js -> GET /hello
import { Route } from 'owebjs';
export default class HelloRoute extends Route { handle() { return { message: 'hello-world' }; }}2) Dynamic params
Section titled “2) Dynamic params”Put parameter names in brackets.
routes/users/[id].js -> GET /users/:id
import { Route } from 'owebjs';
export default class UserRoute extends Route { handle(req) { return { id: req.params.id }; }}3) HTTP method suffix
Section titled “3) HTTP method suffix”Use filename suffixes when an endpoint is not GET.
routes/auth/login.post.js -> POST /auth/login
Supported suffixes: .get, .post, .put, .patch, .delete
import { Route } from 'owebjs';
export default class LoginPostRoute extends Route { handle(req, res) { return res.status(201).send({ method: req.method, body: req.body }); }}4) Matcher params
Section titled “4) Matcher params”Matcher params add filename-level validation.
routes/posts/[id=integer].js + matchers/integer.js
export default function integerMatcher(value) { return /^-?\d+$/.test(String(value));}Then register the matcher directory:
await app.loadRoutes({ directory: 'routes', matchersDirectory: 'matchers', hmr: { enabled: true, matchersDirectory: 'matchers', },});If the matcher returns false, the route is treated as not matched.