Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPatrick Perkins
14,619 PointsGetting 404 in Postman on PUT request.
The route is valid in Postman on a GET request because the json quote is returned. However, when changing to a PUT request and sending json in the body, I get a 404 error but am not receiving the error message "Quote not found" from the code.
Here is my code:
app.put('quotes/:id', async (req,res) => {
try {
const quote = await records.getQuote(req.params.id);
if (quote) {
quote.quote = req.body.quote;
quote.author = req.body.author;
await records.updateQuote(quote);
res.status(204).end();
} else {
res.status(404).json({message: "Quote not found"})
}
records.updateQuote(quote)
} catch (err) {
res.status(500).json({message: err.message});
}
})
2 Answers
Zimri Leijen
11,835 Pointsapp.put('/quotes/:id', async (req,res) => { // you were missing the '/' before quotes
try {
const quote = await records.getQuote(req.params.id);
if (quote) {
quote.quote = req.body.quote;
quote.author = req.body.author;
await records.updateQuote(quote);
res.status(204).end();
} else {
res.status(404).json({message: "Quote not found"})
}
records.updateQuote(quote)
} catch (err) {
res.status(500).json({message: err.message});
}
})
Pablo Calvo
13,044 PointsSame happened here... lol, thanks, been 3 days stuck looking at it
Patrick Perkins
14,619 PointsPatrick Perkins
14,619 PointsGotta love coding. I noticed I didn't place a "/" in front of my route.