Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 2.2.0 URLMappings: Any way to use same URL with Different Verb

I have the following:

"/api/users"(controller: "user") {
   action = [GET:"list"]
}

Doing a call to http://localhost:8080/platform/users I get a list of users back. Then I added this:

"/api/users"(controller: "user") {
   action = [POST:"save"]
}

And now I get a 404 and it is not hitting either method in UserController. I'd like to be able to use the same URL with the verb controlling which action. Am I doing this wrong or does Grails not support this?

like image 899
Gregg Avatar asked Dec 22 '12 03:12

Gregg


2 Answers

From the Grails docs: URL Mappings

static mappings = {
   "/product/$id"(controller:"product") {
       action = [GET:"show", PUT:"update", DELETE:"delete", POST:"save"]
   }
}

For your case:

"/api/users"(controller: "user") {
   action = [GET:"list",POST:"save"]
}
like image 112
James Kleeh Avatar answered Oct 19 '22 23:10

James Kleeh


Check your userController to see if there is allowedMethods defined accordingly like this:

class UserController {

    static allowedMethods = [save: "POST", list: "GET"]

    def list() {
    .....
    }

    def save() {
    .....
    }
}
like image 24
coderLMN Avatar answered Oct 20 '22 00:10

coderLMN