0.6.7 • Published 4 months ago

express-json-router v0.6.7

Weekly downloads
2
License
MIT
Repository
github
Last release
4 months ago

express-json-router

Express router wrapper to send json response

Test Status Publish Status NPM

Installation

$ npm install express-json-router
$ yarn add express-json-router

Usage

const express = require('express');
const JsonRouter = require('express-json-router');
const router = new JsonRouter();
const clientErrors = JsonRouter.clientErrors;
const app = express();

// Optional error message provider
// Default to `error.message || error._message || error`
JsonRouter.errorMessageProvider = function (error) {
  // Place an error parser here and return the new message.
  return 'It is a processed error message';
};

router.all('/all-route', () => 'all-route');
router.get('/get-route', () => 'get-route');
router.post('/post-route', () => 'post-route');
router.put('/put-route', () => 'put-route');
router.delete('/delete-route', () => 'delete-route');

router
  .route('/route-route')
  .all((req, res, next) => next())
  .get(() => 'route-get-route')
  .post(() => 'route-post-route')
  .put(() => 'route-put-route')
  .delete(() => 'route-delete-route');

router.get(
  '/next',
  (req, res, next) => next(),
  () => 'next-test'
);

router.get('/unauthorized-error', () => {
  throw new clientErrors.UnauthorizedError();
});

app.use('/', router.original).listen();

Client Errors

MIT Licensed

0.6.7

4 months ago

0.7.0

6 months ago

0.6.6

9 months ago

0.6.3

9 months ago

0.6.5

9 months ago

0.6.4

9 months ago

0.6.2

10 months ago

0.6.1

1 year ago

0.6.0

1 year ago

0.4.1

2 years ago

0.3.1

2 years ago

0.5.1

2 years ago

0.2.1

2 years ago

0.2.0

3 years ago

0.1.3

3 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago