The HTTP_ACCEPT header is used by web-clients to tell your application what type of response it wants and is the magic behind the very slick responds_to method of your controller. Rails edge now supports the case when you want to specify the type of response as a request parameter and not as an http header.
Currently, when a client sends an Http request to your app with an HTTP_ACCEPT header value of application/xml, you can do this in your controller to render the response as the appropriate XML:
# From example at:
# http://api.rubyonrails.com/classes/ActionController/MimeResponds/InstanceMethods.html#M000062
...
respond_to do |wants|
wants.html
wants.xml { render :xml => @people.to_xml }
end
...
Great, we’ve got an easy way to render the type of response the client has asked for without duplicating our controller logic. But, we don’t yet have a way to trigger this little bit of magic from anything other than the Http header – not a very friendly place to hang out. That’s what changeset 4384 addresses – the ability to determine the requested response type from a normal http parameter instead of the http header.
How it Works
Telling the request what response type you want is now as easy as adding a format parameter to your request and using the same respond_to determination as before. So this request sent from your web browser (which always sends an HTTP_ACCEPT header value of text/html or */*)
http://host/action?format=xml
Will override the supplied HTTP_ACCEPT header and will trigger the xml block of respond_to in your controller (imitating HTTP_ACCEPT = application/xml)
Overall a great way to programatically specify the response type without monkeying with http headers.
For further reading on the topic, here are some related posts:- Discovering HTTP #1: The Accept header
- Content Negotiation And Rails
- Rails Weenie question: respond_to and redirects
- respond_to API
tags: http headers, rubyonrails, rails

map.connect '/post/show', :controller => 'post', :action => 'show', :format => 'xml', :requirements => { :subdomain => 'api' }This keeps you from having to fiddle with HTTP header params, which just feels wrong, while also being a more portable solution as the config is contained solely within your Rails app.