Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript REST APIs with Express Create, Read, Update, Delete Create a New Quote

Masha Blair
Masha Blair
13,005 Points

In REST-API w/ Express class, I can't create a new quote by sending a POST request to my local server w/ Postman.

In REST-API w/ Express class, I can't create a new quote by sending a POST request to my local server w/ Postman.

Everything seems to be exactly the same as teachers code and actions -- my local server is running, the code is the same, but when I hit 'Send' in Postman with a new quote JSON, my status code is 404 Not Found. So no new record is created in data.json

Can someone please help?

2 Answers

Here is the code

app.post("/quotes", async (req, res) => {
  const quote = await records.createQuote({
    quote: req.body.quote,
    author: req.body.author,
  });
  res.json(quote);
});
Masha Blair
Masha Blair
13,005 Points

Never mind, when I tried 'Send' again in 5 minutes, it worked and I got 200 OK status. Weird!

Chai Chong Teh
Chai Chong Teh
25,709 Points

I initially stumbled upon the same thing, then I found out that it was because of the typo at Postman.