I am seeking guidance rather than a direct answer, as this is crucial for my final exam. I require a starting point to help me fill in the missing pieces. It's important to note that local storage cannot be used to store user input.
// POST handler adds a task to a list
app.post('/task', (req, res) => {
res.set('Content-Type', 'application/json');
/*
Input: data coming into this handler will be in the form:
{"task": "mytask"}
You can see contents of the incoming request with:
console.log(req.body.task). "req" is the request
and within it, the property req.body holds the incoming data
above from the client request, hence "task" is a property of
that incoming request data object.
Output: This handler should send the datastore back to
the client with a 201 response code if successful, and return
and 400 response code with no response body if the task already
exists in either the TODO or Completed list.
*/
console.log(req.body.task);
/*
YOUR CODE HERE
*/
// send 201 status with no response body
res.status(201).send({})
});
I have multiple tabs open with various articles on node and post methods, but grasping the concept proves to be challenging at times.
Here is what I have for datastore:
let taskDatastore = {
"todo": [
"finish test 2",
],
"completed": [
"read the test instructions",
],
};