Reputation: 31290
Grails supports content negotiation from 3 different sources:
The question is, what does it do when it get content information from more than one place, especially when they don't agree with each other?
For example, what would happen if Grails recieved a request like the following:
URL: http://example.com/book/list.html?format=json
Accept: application/xml
The Accept header would resolve to xml, the URI extension would resolve to html, and the parameter would resolve to json.
What would this do:
import grails.converters.*
class BookController {
def list() {
def books = Book.list()
withFormat {
html bookList: books
xml { render books as XML }
json { render books as JSON }
}
}
}
Upvotes: 2
Views: 925
Reputation: 11035
For Grails 2.0.0RC3 the following will return the html block.
curl -v -H "Accept: application/xml" http://localhost:8080/book/book/list.html?format=json
The order of precedence is:
Note that in order to use the Accept header you must change the following parameter in the grails-app/conf/Config.groovy file (default is false):
grails.mime.use.accept.header = true
Upvotes: 5