"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Controllers/respond.html" (14 Sep 2022, 62860 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:

Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)



Attempts to return the most appropriate type for the requested content type (specified by either the Accept header or file extension)


// pick the best content type to respond with
respond Book.get(1)

// pick the best content type to respond with from the given formats
respond Book.get(1), formats: ['xml', 'json']


The respond method uses Content Negotiation to respond with the most appropriate content type. See the documentation on REST support for more information.

If a view is picked for rendering then a model will automatically be calculated to pass to the view.

The following table summarizes this convention:

Example Argument Type Calculated Model Variable

respond Book.list()



respond Book.get(1)



respond( [1,2] )



respond( [1,2] as Set )



respond( [1,2] as Integer[] )




  • object - The object to render

  • arguments - Named arguments.

Supported arguments:

  • view - The view to use in case of HTML rendering

  • model - The model to use in case of HTML rendering

  • status - The response status

  • formats - A list of formats to respond with

  • includes - Properties to include if rendering with the converters API

  • excludes - Properties to exclude if rendering with the converters API

Due to the way Groovy works, while responding with a Map and arguments it is important to respond in this manner respond([:], status: 200) instead of this manner respond([:], [status: 200]). Failure to do so will result in the arguments being reversed.