REST - Tradeoffs between content negotiation via Accept header versus extensions
- by Brandon Linton
I'm working through designing a RESTful API. We know we want to return JSON and XML for any given resource. I had been thinking we would do something like this:
GET /api/something?param1=value1
Accept: application/xml (or application/json)
However, someone tossed out using extensions for this, like so:
GET /api/something.xml?parm1=value1 (or /api/something.json?param1=value1)
What are the tradeoffs with these approaches? Is it best to rely on the accept header when an extension isn't specified, but honor extensions when specified? Is there a drawback to that approach?