We'll learn an alternative way of creating API routes using the next-connect package. next-connect gives us an alternative that would feel familiar to anyone that has worked with Express in the past.
import nextConnect from "next-connect"
const handler = nextConnect({
onNoMatch: (req, res) => res.status(404).json({message: 'not found'})
})
.get((req, res) => res.status(200).json({message: 'GET!'}))
.post((req, res) => res.status(200).json({message: 'POST!'}))
.patch((req, res) => res.status(200).json({message: 'PATCH!'}))
.put((req, res) => res.status(200).json({message: 'PUT!'}))
.delete((req, res) => res.status(200).json({message: 'DELETE!'}))
export default handler