Mapping exceptions to HTTP status codes in REST web services

When building REST web services in .NET, what is the most "RESTful" way of mapping System.ArgumentNullException and System.ArgumentException to HTTP status codes? My first guess would be to use HTTP 400/Bad Request with an appropriate description.What is the recommended best practice when mapping exceptions to HTTP status codes?

Answers


In general, the 4xx status codes tell the client that the request failed but may succeed if the request i smodified. The 5xx codes inform the client about problems that where the client has no influence.

So the first distinction you have to make is between 4xx and 5xx codes, i.e. tell the client if it should retry or not.

HTTP 400 "Bad Request" should be used if the request was indeed syntactically malformed, incomplete, contradicting or otherwise basically wrong. Additionaly it may be a valid default status in the 4xx range, if no other status seems appropriate and you believe the client needs only to modify the request to succeed.


Need Your Help

Scroll event doesn't fire unless page moves

javascript jquery javascript-events scroll

I'm looking to get an event to fire when one scrolls "up" from $(window).scrollTop == 0.

kendo splitter: hover event

hover kendo-ui splitter

I would like to run code in the hover event in the kendo-ui splitter.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.