Created
November 9, 2021 12:25
-
-
Save tpjnorton/ac814805485f8bb2a2652425eefd0f1c to your computer and use it in GitHub Desktop.
A more complicated Next API route handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function handler(req, res) { | |
if (req.method === 'POST') { | |
checkAuth(); | |
doSomething(); | |
res.status(200).json({ name: 'John Doe' }) | |
} else if (req.method === 'DELETE') { | |
checkAuth(); | |
doSomethingElse(); | |
res.status(200).json({ status: 'Deleted' }) | |
} else if (req.method === 'GET') { // no auth | |
const items = doAThirdThing(); | |
res.status(200).json({ data: items }) | |
} else { | |
res.status(405).text('Method Not Allowed') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment