// 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']
respond
Purpose
Attempts to return the most appropriate type for the requested content type (specified by either the Accept
header or file extension)
Examples
Description
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 |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters:
-
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.
|