/proto

A simple method (and hopefully middleware) routing layer for serverless Node.js APIs.

Primary LanguageTypeScriptMIT LicenseMIT

Proto for Vercel Node APIs

npm

This is a super-simple (not production ready) method/middleware routing layer designed for running Node.js APIs with Vercel.

Example repositories:

This can probably also be used with Next.js too.

Installation

npm install @peterjskaltsis/proto
// or
yarn add @peterjskaltsis/proto

Usage

proto allows you to define functions to be called for different HTTP methods on a single endpoint, in a clean and simple way.

// api/index.js
import proto from '@peterjskaltsis/proto'

const router = proto()

router.get((req, res) => {
  res.send('Hello there!')
})
  
router.post((req, res) => {
  res.json({ hello: 'there!' })
})

router.put(async (req, res) => {
  res.end('async/await enabled')
})

router.patch(async (req, res) => {
  throw new Error('Errors can be caught and handled.')
})

export default router

Contributing

Please see my contributing.md.

License

MIT