Skip to content

Instantly share code, notes, and snippets.

@gfxargentina
Created March 16, 2023 00:46
Show Gist options
  • Save gfxargentina/caedb26f04e6bae3b70fab756db43a7c to your computer and use it in GitHub Desktop.
Save gfxargentina/caedb26f04e6bae3b70fab756db43a7c to your computer and use it in GitHub Desktop.
api nextjs
//controlador
import signCloudinary from '../sign-cloudinary';
export default function handler(req, res) {
//type of request
const { method } = req;
switch (method) {
case 'GET':
res.status(200).json({ msg: 'GET Request' });
break;
case 'POST':
signCloudinary(req, res);
break;
case 'PUT':
res.status(200).json({ msg: 'PUT Request' });
break;
case 'DELETE':
res.status(200).json({ msg: 'DELETE Request' });
break;
default:
res.setHeader('Allow', ['GET', 'POST', 'PUT', 'DELETE']);
res.status(405).end(`Method ${method} Not Allowed`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment