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 trialSusan Rusie
10,671 PointsWhy did I get the message "Can't PUT/api/todos/82b8724b911073816b5bd26"?
I followed all of Huston's instructions when using Postman, changing "completed" to "true" when I tried to do a put request towards the end of the video "Editing Data With PUT Routes In Express". I was supposed to get an error message. Here is my code for my index.js:
'use strict';
var express = require('express');
var Todo = require('../models/todo');
//var todos = require('../../mock/todos.json');
var router = express.Router();
router.get('/todos', function(req, res) {
Todo.find({}, function(err, todos) {
if (err) {
return res.status(500).json({ message: err.message });
}
res.json({ todos: todos });
});
});
router.post('/todos', function(req, res) {
var todo = req.body;
Todo.create(todo, function(err, todo) {
if (err) {
return res.status(500).json({ err: err.message });
}
res.json({ 'todo': todo, message: 'Todo Created' });
})
});
router.put('/todos/;id', function(req, res) {
var id = req.params.id;
var todo = req.body;
if(todo && todo._id !== id) {
return rest.status(500).json({err: "Ids don't match!"})
}
Todo.findByIdAndUpdate(id, todo, {new: true}, function(err, todo) {
if (err) {
return res.status(500).json({err: err.message});
}
res.json({'todo': todo, message: 'Todo Updated.'});
})
});
// TODO: Add DELETE route to remove existing entries
module.exports = router;
2 Answers
Sergey Podgornyy
20,660 PointsI guess, first of all because use write
router.put('/todos/;id', function(req, res) {});
instead of
router.put('/todos/:id', function(req, res) {});
And I think, if you want to get response from PUT /api/todos/82b8724b911073816b5bd26
, you need to implement logic like:
router.put('/api/todos/:id', function(req, res) {});
Amanda Free
11,375 PointsI keep getting the message "Unexpected 'C'" in Postman. My code looks the same as Huston's, and it's running fine in the browser, so I'm not sure what the issue is.
Susan Rusie
10,671 PointsI got that too at one point, Make sure you check your code. I had a semi-colon instead of a colon between the todos/:id and that seemed to fix the problem. You can check your code against mine as everything else is right and hopefully, that will fix the problem.
Susan Rusie
10,671 PointsSusan Rusie
10,671 PointsThat worked. Thank you.
Sergey Podgornyy
20,660 PointsSergey Podgornyy
20,660 PointsYou are welcome