Documentation: Add section about content negotiation

Bug #605369 reported by Niko Schmuck
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Fix Committed
Undecided
Peter Hilton

Bug Description

It would be great if the routes or controller documentation would shortly describe how to make use of the content negotiation provided by Play! framework (and discuss the format fallback strategy).

Related Google Groups Thread: http://groups.google.com/group/play-framework/browse_thread/thread/ad609521609c8018/e38821f9102b45a4

Guillaume Bort (27 Okt. 2009, 16:40)

In fact if the Accept header is not suitable for you, you can even use
different URL path. For example, in conf/routes:
GET /index Application.index
GET /index.xml Application.index(format:'xml')
You can even extract the format information, dynamically from the URL path
GET /index.{format} Application.index

Guillaume Bort (27 Okt. 2009, 16:55)

Currently the only content type resolved by the engine itself are only
txt,html,json and xml.
But I agree it's lame, and surely it should be pluggable.
However you can easily do it yourself either by specifying the correct
format value for a special URL in the route file, or using a @Before
interceptor that examine the Accept header:
    @Before
    static void setFormat() {
        if(request.headers.get("accept").value().equals("text/v-card")) {
            request.format = "vcf";
        }
    }
And it will finally render the index.vcf template and set
automatically response mime-type to text/v-card.

Niko Schmuck (niko-nava)
tags: added: documentation
Revision history for this message
Peter Hilton (pedro-lunatech) wrote :

I'll see if I can pull all of this together into a new documentation section.

Changed in play:
assignee: nobody → Peter Hilton (pedro-lunatech)
Revision history for this message
Peter Hilton (pedro-lunatech) wrote :

I have published a draft at http://www.lunatech-research.com/archives/2010/07/26/play-framework-content-negotiation which I am now going to adapt for the Play 1.0.x documentation.

Changed in play:
status: New → In Progress
Revision history for this message
Peter Hilton (pedro-lunatech) wrote :

I've expanded the 'Setting content types' section, and added an 'HTTP content negotiation' section to the routes documentation, committed in revision 1086.

Changed in play:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.