File size: 529 Bytes
1ddbce4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;