intridea/grape — pull request #147 by dblock (2012-02-22 21:10:11+00:00)
Title: Frontier: enable default_format to actually do something

When the format from Accept headers was fixed, it took over whatever you specify in default_format. This seems logical. But we no longer can force a specific format on the server and now have to respect accept headers. This may be ok for new APIs, but there're plenty of clients that say they accept text only, but are getting json back. It's also, interestingly, the default behavior of RSpec, so now you have to go back in thousands of API tests and change everything to add { 'HTTP_ACCEPT' => 'application/json' }.

I added :format, which simply inserts itself in this logic and a bunch of tests. It's basically the API format irrespectful of what's in the Accept request headers.

* If the client says he wants a file.txt, then we give him text. All is good here.
* If the server specifies `format`, use that.
* If the client says "i accept application/json", you want to give him JSON. All seems good here.
* If the client says "i accept something else", you want to give him the default_format.