Synopsis
Express middleware that adds sendStatusJson helper method to the Express's response object.
Quick start
Start with running npm install send-status-json --save
for your app. Then, register it as a middleware to express app:
;; const app = ; app;
Then you can use it to return simple response. First parameter is status code and second is an object with wanted custom properties. Properties passed in second parameter are assigned to the root of response.
app;
Response above result to the json response like this. Status code of http response is also set.
Usage without custom properties is simple.
app;
If you are using TypeScript, you can extend Express Response interface with your own and set types for sendStatusJson method.
;; interface Response extends expressResponse sendStatusJson: SendStatusJsonFunction;
Build
Run npm run build
to compile typescript files to javascript es5. Builded content will be inserted in ./dist folder.
Tests
Run npm test
to run tests in mocha.
License
MIT.