Learn Express, Middleware - using postman to post to the 'spiceracks'


#1

Hi!

Cannot find the category ‘Learn Express’, trying to post here - if you could direct me to the proper category I will be glad.

now solved, am I able to delete this post ?

I am testing this and I would like to post and add a spice to the ‘spice-rack’ using ‘post’.
https://www.codecademy.com/courses/learn-express-middleware/lessons/router-parameters/exercises/merge-params?action=resume_content_item&course_redirect=learn-express

The outcome from GET (http://localhost:4001/spice-racks ) is the following:

[
    {
        "id": 1,
        "location": "Kitchen Countertop"
    },
    {
        "id": 2,
        "location": "Pantry"
    },
    {
        "id": 3,
        "location": "Outdoor Barbecue"
    }
]

The post-function is like the following ( I have added the console.log)

app.post('/spice-racks/', (req, res, next) => {
  const newRack = req.body.spiceRack;
  console.log('posting ',newRack);
  newRack.id = nextSpiceRackId++;
  console.log('posting id',newRack.id);
  spiceRacks.push(newRack);
  res.send(newRack);
});

(1) choosing the ‘post’ in postman and entering http://localhost:4001/spice-racks
(2) chosing the ‘body’ , then ‘raw’
(3) {“spiceRack”: {“location”:“in the cottage”}}
(4) press ‘send’

This works now :slight_smile:

the outcome of get is now .

[
    {
        "id": 1,
        "location": "Kitchen Countertop"
    },
    {
        "id": 2,
        "location": "Pantry"
    },
    {
        "id": 3,
        "location": "Outdoor Barbecue"
    },
    {
        "id": 4,
        "location": "in the cottage"
    }
]

So the question is no longer a question, Am I able to delete this post ?

best, Ingo


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.