10.7 The REST Profile
Since Grails 3.1, Grails supports a tailored profile for creating REST applications that provides a more focused set of dependencies and commands.
To get started with the REST profile, create an application specifying rest-api
as the name of the profile:
$ grails create-app my-api --profile rest-api
This will create a new REST application that provides the following features:
Default set of commands for creating and generating REST endpoints
Defaults to using JSON views for rendering responses (see the next section)
Fewer plugins than the default Grails plugin (no GSP, no Asset Pipeline, nothing HTML related)
You will notice for example in the grails-app/views
directory that there are *.gson
files for rendering the default index page and as well as any 404 and 500 errors.
If you issue the following set of commands:
$ grails create-domain-class my.api.Book
$ grails generate-all my.api.Book
Instead of CRUD HTML interface a REST endpoint is generated that produces JSON responses. In addition, the generated functional and unit tests by default test the REST endpoint.