router-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i router-adapter

Weekly Downloads

1

Version

0.5.0

License

ISC

Unpacked Size

18.1 kB

Total Files

21

Last publish

Collaborators

  • saulogt