0.5.0 • Published 6 years ago

router-adapter v0.5.0

Weekly downloads
194
License
ISC
Repository
github
Last release
6 years ago

router-adapter

This package is intended to simplify the express router list as well as separate the logic from the http handling.

Install

npm i router-adapter --save

Usage:

import { routerAdapter } from 'router-adapter'

app.get('/my-entrypoint/:id', routerAdapter((req) => getObject(req.params.id))

Instead of this:

app.get('/my-entrypoint/:id', (req, res) => {
  getObject(req.params.id)
  .then((value) => {
    res.status(200).json(value)
  })
  .catch((e) => {
    res.status(500).json(e)
  })
})

Requirements

-The handler function must return a Promise -If you want to return different error codes other than 500, the promise can be rejected with an instance of HttpError.

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago