express-object-router
This library facilitate describing endpoints for REST API servers. The main feature of this library is determining method, path, controller, middlewares, and validation of query object, url object and body object with one object.
If you have any ideas or question just leave issue here
Getting Started
Follow to install module
npm install express-object-router --save
- Look example.
Example
More examples here
Library configuration
/* app.js */const express = ;const createRouter = ;const path = ; const customMiddleware = { requser = id: 10 name: 'John' age: 20 ; ;}; const app = ; const router = ; app;app;
Describing routes
/* routes/main.js */const GET POST = ;const joi = ; const testCtrl = req /* express req object */ res /* express res object */ next /* express next function */ reply /* function for sending reply to client */ error /* function calls error */ headers /* headers object from req */ params /* req.params */ body /* req.body */ query /* req.query */ user /* property which determined in "extraControllerProps" */ ;; const testMiddleware = req /* express req object */ res /* express res object */ next /* express next function */ headers /* req.headers */ error /* function calls error */ pass /* function pass to next middleware */ props /* values from "middlewaresProps" */ setToReq /* function assign property to req object */ params /* req.params */ body /* req.body */ query /* req.query */ ;;moduleexports = method: GET /* http method */ path: '/article' /* route path */ controller: testCtrl /* controller function */ middlewares: testMiddleware /* middlewares for this route */ middlewaresProps: {} /* props for middleware */ validation: /* validation */ query: limit: joi offset: joi body: {} params: {} ;
Changelog
[1.3.4] - 2018-05-25
Updated
errorP
now avaliable from package.reply
now supports promises as argument
[1.3.3] - 2018-04-18
Added
errorP
fuction to controller params
[1.3.1] - 2018-04-09
Updated
- interface of
build-docs
has been changed - fix
apidoc
text generation
[1.3.0] - 2018-04-06
Added
- Add
info
to theRoute
interface - Add cli command
oe-router build-docs
(alpha) - Remove spread operator for node 6 compatibility
[1.2.0] - 2017-12-20
Added
- Update
package-lock.json
- Add
body
,params
andquery
to middleware object of arguments
MIT License
Copyright (c) 2017 Artur A.