1

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.

2
  • 1
    Did you setup "/books"(resources:"book") in your UrlMappings.groovy? Commented Sep 16, 2014 at 19:04
  • 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. Commented Sep 16, 2014 at 21:14

1 Answer 1

4

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")
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Would be nice if the documentation stated that. They way all of us here read it; was implicit.
We were all being tripped up on the default "/$controller/$action?/$id?(.$format)?" UrlMapping, thinking something else was registering that explicitly.
It's okay. Given all the options available it's difficult for some people to understand what the implementation of each approach means. If I get time today I will see about forking the documentation or at least creating a JIRA. Unless you beat me to it. (:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.