nextjs-api-handler
v1.0.7
Published
The most EZ way to handle your Next JS API's requests !
Downloads
4
Maintainers
Readme
NextJS API Handler
The most EZ way to handle your Next JS API's requests !
Install
Install with npm:
$ npm i --save nextjs-api-handler
Usage
Import :
import { requestHandler } from "nextjs-api-handler";
export default async (req: NextApiRequest, res: NextApiResponse) => requestHandler(req, res, {
GET: () => getHandler(req,res),
POST: () => postHandler(req, res),
//
})
const getHandler = (req: NextApiRequest, res: NextApiResponse) => res.status(200).send("OK");
const postHandler = async (req: NextApiRequest, res: NextApiResponse) => {
// handle your route
}
// TODO : usage of errorHandler