npm.io
0.5.0 • Published 8 years ago

router-adapter

Licence
ISC
Version
0.5.0
Deps
4
Size
18 kB
Vulns
0
Weekly
0

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.