tags:

views:

43

answers:

2

I'm writing a simple url-based API that retrieves data and sends it back in one of a few formats (XML, JSON, CSV). I'm kind of on the fence about how to handle error responses. If the user supplies a format then I can just send the response in that format, but what about cases where the user requests an unsupported format?

Is it preferable then to just pick one arbitrarily and go with that? Should I look at something like sending HTTP responses a la REST APIs instead so it's a little more format agnostic?

+2  A: 

If you are creating an API, going REST seems to make a lot of sense. Do have format choices but document the default, whatever it maybe be and return the error message in that format, along with the proper response code indicating the general reason for the error.

Here's a little about error handlilng in REST, if you go that round.

http://www.oreillynet.com/onlamp/blog/2003/12/restful_error_handling.html

Hans
Yeah I like that approach as well. Thanks for the link.
JustinB
A: 

When a client wants an unsupported format you can respond with a 406 Not Acceptable

Hanse