visionmedia / express-resource

Resourceful routing for Express
1.41k stars 140 forks source link

Unimplemented methods should return 405 status code #49

Closed rybesh closed 5 years ago

rybesh commented 12 years ago

Currently HTTP requests to a resource that specify a method unimplemented by that resource return a 404 Not Found status code. That is misleading, since the resource can be found—it just doesn't allow that method. It should return a 405 Method Not Allowed in this case.

This behavior (or at least the "Cannot [METHOD] [PATH]" message") seems to be coming from the connect lib; it's not clear to me whether it can or should be fixed there, or in express-resource.

piotrek-r commented 12 years ago

Shouldn't this be 501? 4xx indicates client-side problems and not implementing a method is more like server-side thing to get done.

rybesh commented 12 years ago

It's a client-side problem because the client has attempt to use a method unsupported by the resource. It's analogous to a 404 (where the client has requested a resource that doesn't exist).

conradev commented 11 years ago

It's simple enough to implement:

var errorResponse = function(error) {
  return function(req, res) { res.send(error); };
}
app.delete('/notdeletable', errorResponse(405));

But I agree. The default error code for endpoints that exist but do not support the method should be 405

hgwood commented 8 years ago

Any news on this?

vendethiel commented 8 years ago

This project is long dead

hgwood commented 8 years ago

My bad. PR for this feature in Express 4 is here: https://github.com/strongloop/express/pull/2703.