common-routes
Simple express/knex/bookshelf util for common routes that emerge on every rest api.
See docs for more details.
Install
# you'll need express, knex and bookshelf too npm install common-routes --save
Dependencies
- Express (with body-parser/json middleware)
- Bookshelf (and the bookshelf-page plugin)
- Knex
- the sql driver for your database
Usage
// src/routes/area.jsconst commonRoutes = ;const knex Bookshelf = ;const router = ; const Area = BookshelfModel; const withRelated = "state"; commonRoutes; moduleexports = router Area;
Then require this router on your main app:
// src/main.jsconst express = ;const json = ;const app = ; app; app; // ...
Once you pass this router to your express app, the following routes will be available:
route | verb | purpose |
---|---|---|
/area/list | GET | Lists all areas. Can pass page and pageSize as query parameters. |
/area/count | GET | Counts all areas. |
/area/:id | GET | Gets one area by id. the real name of the key column the model already knows. |
/area/save | POST | Inserts a new entity. |
/area/save | PUT | Updates an entity. It must have a valid ID |
/area/:id | DELETE | Detetes one entity. with the given id |
See docs for more details.