-
Notifications
You must be signed in to change notification settings - Fork 0
next.js examples
Centell edited this page Apr 27, 2020
·
2 revisions
pages/api/demo/[id].js
export default (req, res) => {
const {
query: { id },
method,
} = req;
switch (method) {
case 'GET':
res.status(200).json({ id });
break;
case 'POST':
res.status(200).json({ id });
break;
default:
res.setHeader('Allow', ['GET', 'POST']);
res.status(405).end(`Method ${method} Not Allowed`);
}
};
pages/api/demo/index.js
export default (req, res) => {
const {
method,
} = req;
switch (method) {
case 'GET':
res.status(200).json({ id: '0' });
break;
case 'POST':
res.status(200).json({ id: '0' });
break;
default:
res.setHeader('Allow', ['GET', 'POST']);
res.status(405).end(`Method ${method} Not Allowed`);
}
};