1.0.2 • Published 3 years ago
next-methods v1.0.2
Split next.js handlers by http methods
Installation
npm i next-methods --save
Usage
Usage:
import { withMethodHandler } from 'next-methods';
export default withMethodHandler({
'PUT': handlePut,
'GET': handleGet,
);
Example combining with other wrappers:
export default withApiAuthRequired(
withMethodHandler({
'PUT': handlePut,
'GET': handleGet,
})
);
By default it will return 404 for unhandled methods but you can override the behavior as follows:
export default withMethodHandler({
'PUT': handlePut,
'GET': handleGet,
'other': (req, res) => res.status(400).end()
);
License
MIT 2021 - José F. Romaniello