1
votes

I'm a bit confused on now this should be working. The documentation says: http://grails.org/doc/latest/guide/single.html#extendingRestfulController

9.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 the grails.rest.RestfulController super class. For example:

class BookController extends RestfulController { static responseFormats = ['json', 'xml'] BookController() { super(Book) } }

To customize any logic you can just override the appropriate action. The following table provides the names of the action names and the URIs they map to:

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

I have created the BookController as well as the associated Book domain class, but i notice that I cannot access (Bootstrap added books) the books via the documented uri:
/books/${id}

I am able to access it using the non-plural domain name and the action:
/book/show/1

When I try to add @Resource(uri='/books') to the Book domain class that doesn't help either. Does grails not support his anymore? Do i have to use the action verbs?

I am using grails 2.4.2

Thanks.

1
Did you setup "/books"(resources:"book") in your UrlMappings.groovy? - Joshua Moore
You are correct, by adding that in it does work. Thank you. It seems that if i use the @Resource in the domain it works as desired. If i create a controller that extends RestfulController the mappings are overridden with the action bases paths. The documentation is very misleading. - Julian

1 Answers

4
votes

When you extend RestfulController you are responsible for setting up the resource mapping within the UrlMappings.groovy. Unlike the @Resource annotation on your Domain class.

For example:

// UrlMappings.groovy
"/books"(resources:"book")