(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']

If you simply wish to augment the calculated model then you can do so by passing a model argument:

respond Book.list(), [model: [bookCount: Book.count()]]

The above example will produce a model like [bookList:books, bookCount:totalBooks], where the calculated model is combined with the model passed in the model argument. You could also pass the Map to repond method such as respond([bookList:Book.list(), bookCount:Book.count()])

By default, the respond method will select the view based on actionName. But, if you wish to change the default view and use some other view then you could do so as:

respond Book.list(), [view: 'other', model: [bookCount: Book.count()]]


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 (Named arguments):

  • view - The view to delegate the rendering to

  • model - The additional model to use in 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.