This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Services and the fly likes RESTful web services and status code philosophy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "RESTful web services and status code philosophy" Watch "RESTful web services and status code philosophy" New topic
Author

RESTful web services and status code philosophy

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

OK, for a GET specifying a record (or some such) that doesn't exist, the response has status code 404 (not found). That's easy.

But what about a PUT that fails because the user gave bad input?

404 doesn't seem to cut it. And there doesn't seem to be any other pre-defined status codes that don't already have some heavy HTTP semantics associated with them.

What's the appropriate return code?

Overall, what's the philosophy to choosing status codes for a RESTful service?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Originally posted by Bear Bibeault:
But what about a PUT that fails because the user gave bad input?


400 "Bad Request"

It's commonly used when the client submits a representation along with a put or POST request, and the representation is in the right format, but doesn't make any sense.


Overall, what's the philosophy to choosing status codes for a RESTful service?


"Appendix B: The HTTP Response Code Top 42" from RESTful Web Services


"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

Thanks Peer!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RESTful web services and status code philosophy
 
Similar Threads
Need urgent help
how to forward to another page, if location.href page is not found
Call a function before Ajax success
Login page in eclipse
response.Status codes