Content Negotiation Module
The content negotiation module helps using content types which are not directly supported by the Play! framework.
For this it provides a list of default types which are automatically mapped to the correct template. You can also
define your own mappings using a simple properties file.
Enable the content negotiation module
In the /conf/application.conf file, enable the content negotiation module by adding this line:
# The content negotiation module
module.cnm=${play.path}/modules/cnm
Using built-in content types
The content negotiation module comes with several content types enabled by default . To make use of them you only
have to enable the module (see above).
Define a your own content type
When you want to use your own content type you have to create a single properties file which holds the mapping
between the content type and the template format you wish to use for that content type. Then you have to specify that
file in your /conf/application.conf file using the content.types key.
Example
For example if you want to map the content type application/vnd.com.example.play+xml to the .play format you add the
following line
application/vnd.com.example.play+xml=play
to an empty file. Save the file inside the /conf/ directory and name it types. Then reference it in your
/conf/application.conf file as shown below:
# Allowed content types
content.types=conf/types
Request a specific content type
Besides defining your own content type and the corresponding template format, you may want at some point to actually use it.
To do so change the Accept header of your HTTP request to be exactly like the content type you want. Defining more then one
content type in the accept header is not yet supported as I’ve not yet found an elegant way to determine if a template format
is available or not. So this
Accept: application/vnd.com.example.play+xml
will work but this will not:
Accept: application/vnd.com.example.play+xml;q=1.0, application/vnd.com.example.play+json;q=0.9
Issue tracking
If you wish to report a bug or wish for a new feature, please use the issue tracker