promise-express-router
Promisify express router. Let you return a promise from router handler and it will convert to a json formatted response. The response format is obey to http-api-design,
Document
How to use
Install
npm install promise-express-router
Normal response
- Code
const app = ;const PromiseRouter = ;const promiseRouter = ;promiseRouter;app;
- Response
Error response
- Code
const app = ;const PromiseRouter = ;const promiseRouter = ;promiseRouter;app;
- Response
Response fields
ok
If server error happens, it will be false. Or it's true.result
Result data.message
A human readable error message.code
Error code.
Customize response format
You can also customize response format.
promiseRouter = { return data: objresult status: objok } { return error_code: objcode stacktrace: objmsg normal: objok };
Example
Compatibility
- Node 4.x
- Node 5.x
License
MIT