Skip to content

Instantly share code, notes, and snippets.

@tomgullo
Created April 24, 2013 12:31
Show Gist options
  • Save tomgullo/5451773 to your computer and use it in GitHub Desktop.
Save tomgullo/5451773 to your computer and use it in GitHub Desktop.
nested REST with Grails
/*
"/book/$id?/$author?/$authorid?"(controller: "book") {
action = [GET:"show", PUT:"update", DELETE:"delete", POST:"save"]
}
*/
class BookController {
def beforeInterceptor = [action:this.&checkAuthor, except:'author']
def checkAuthor() {
if (params.author) { forward(action: "author"); return false; }
}
def show = {
println 'in show'
if (params.id) {
render "{'name':'joe'}"
} else {
render "[{'name':'joe'}, {'name':'sally'}]"
}
}
def save = {
render "saved"
}
def author = {
if (request.method == 'GET') {
println 'here in author get'
render "{'author':'joe'}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment