8.1.5.1 Extending the RestfulController super class - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 2.3.8
8.1.5.1 Extending the RestfulController super class
The easiest way to get started doing so is to create a new controller for your resource that extends thegrails.rest.RestfulController
super class. For example:class BookController extends RestfulController { static responseFormats = ['json', 'xml'] BookController() { super(Book) } }
HTTP Method | URI | Controller Action |
---|---|---|
GET | /books | index |
GET | /books/create | create |
POST | /books | save |
GET | /books/${id} | show |
GET | /books/${id}/edit | edit |
PUT | /books/${id} | update |
DELETE | /books/${id} | delete |
Note that theAs an example, if you have a nested resource then you would typically want to query both the parent and the child identifiers. For example, given the following URL mapping:create
andedit
actions are only needed if the controller exposes an HTML interface.
"/authors"(resources:'author') { "/books"(resources:'book') }
class BookController extends RestfulController { static responseFormats = ['json', 'xml'] BookController() { super(Book) } @Override protected Book queryForResource(Serializable id) { Book.where { id == id && author.id = params.authorId }.find() }}
RestfulController
and overrides the protected queryForResource
method to customize the query for the resource to take into account the parent resource.