apiRoute()
Signature
Section titled “Signature”app.apiRoute(resource, handlers)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
resource | string | Resource name (e.g., 'users'). |
handlers | Object | Boolean | Handler map or true for stubs. |
Patterns
Section titled “Patterns”Manual CRUD
Section titled “Manual CRUD”app.apiRoute("users", { get: listUsers, post: createUser, "/:id": { get: getUser, put: updateUser, delete: deleteUser }});Auto Stubs
Section titled “Auto Stubs”app.apiRoute("todos", true);// Creates 501 stubs for GET/POST /todos, GET/PUT/DELETE /todos/:idCRUD Shorthand
Section titled “CRUD Shorthand”app.apiRoute("users", { crud: { list: (req, res) => res.json([]), create: (req, res) => res.status(201).send(), show: (req, res) => res.json({ id: req.params.id }), update: (req, res) => res.json({ updated: true }), remove: (req, res) => res.status(204).send() }});Path Normalization
Section titled “Path Normalization”'users'→'/users''/api/v1/posts'→ stays the same
apiRoute internally calls addRoute, so middleware chains and nested paths work.