node-restful icon indicating copy to clipboard operation
node-restful copied to clipboard

DELETE 404

Open iladarsda opened this issue 11 years ago • 3 comments

When making a DELETE request using RESTANGULAR (AngularJS), I get

DELETE http://localhost:3000/resources 404 (Not Found)

even though my model clearly states that this method is allow:

var Resource = app.resource = restful.model('resource', mongoose.Schema({
    title: 'string',
    year: 'number',
})).methods(['get', 'post', 'put', 'delete']);

Resource.register(app, '/resources');

What should I check? Please advise.

Thanks

iladarsda avatar Dec 20 '13 15:12 iladarsda

It seems like you're forgetting to include the model id in the restangular delete call.

I.e. it should be hitting the route http://localhost:3000/resources/:id but its not including the id in the path.

Restangular should probably prevent something like this by throwing an error

baugarten avatar Dec 20 '13 19:12 baugarten

Great tip.

It turns out my Restangular config was wrong. I've used MongoLab config as an example; i.e.

RestangularProvider.setRestangularFields({ id: '_id.$oid' });

But, my local MongoDB installation has no _id.$oid, insted it should just read:

RestangularProvider.setRestangularFields({id: '_id'});

iladarsda avatar Dec 20 '13 21:12 iladarsda

it needs proper url, seems like you've missed "id" surppose to be like this: export const deletePost = (id) => axios.delete(${url}/${id}); in your API

Peter-Yatosha avatar Apr 25 '22 19:04 Peter-Yatosha