I just realised that for a Grails controller there is another rendering method 'respond'.
What's the difference between respond and render method if we want to render a view in the controller.
I just realised that for a Grails controller there is another rendering method 'respond'.
What's the difference between respond and render method if we want to render a view in the controller.
The respond method uses content negotiation to respond with the most appropriate content type based on the requests 'ACCEPT' header.
This way the consumer of your site can choose how they wish to be returned data. This may not be the best option if you want to force a specific return type. For example: You are building a REST api and only want to return json or xml, if the user asks for test.html then they may be returned your data in a format that you do not wish to support. Otherwise respond can be an easy way to support multiple return formats without programming them each separately.
Render explicitly defines the format you wish to return your data in :
(Examples from documentation)
More information:
Respond: http://grails.org/doc/latest/ref/Controllers/respond.html Render:http://grails.org/doc/latest/ref/Controllers/render.html