baugarten / node-restful

A library for quickly providing a REST API with express or connect
http://www.baugarten.me/node-restful/
1.32k stars 249 forks source link

DELETE 404 #53

Open iladarsda opened 10 years ago

iladarsda commented 10 years ago

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

baugarten commented 10 years ago

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

iladarsda commented 10 years ago

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'});
Peter-Yatosha commented 2 years ago

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