randt's picture
Add 17 files
1ddbce4 verified
raw
history blame contribute delete
529 Bytes
import { NextApiRequest, NextApiResponse } from 'next';
const handler = (req: NextApiRequest, res: NextApiResponse) => {
const task = {
title: req.body.tasks,
};
// Add task to API
fetch('https://api.example.com/tasks', {
method: 'POST',
body: JSON.stringify(task),
})
.then((response) => response.json())
.then((data) => {
res.json(data);
})
.catch((error) => {
console.error(error);
res.status(500).json({ message: 'Error adding task' });
});
};
export default handler;