1

I am trying to map a JSON api to my controller like:

/api/user/1/location GET --> Controller.getLocation()

/api/user/1/location POST --> Controller.setLocation()

I have tried the following url mapping rule without any luck:

    "/api/$controller/$id/$property" {
        action = {[GET: "get${params.property.capitalize()}", POST: "set${params.property.capitalize()}"]}
    }

Anyone tried something like this

sbglasius
  • 3,104
  • 20
  • 28
Bahadır Yağan
  • 5,577
  • 3
  • 35
  • 39

1 Answers1

2

I tried and succeeded with both:

"/api/$controller/$id/$property"{
     action = {"get"+params.property.capitalize()}            //put all joint into the {} bracelet
}

and

"/api/$controller/$id/$property"{
     action = [GET: "getLocation", POST:"setLocation"]         //remove the {} bracelet
}

but failed to assign dynamic parameters into [GET:'',POST:''] map, for example:

"/api/$controller/$id/$property"{
     action = {["POST": "set"+params.property.capitalize(), "GET": "get"+params.property.capitalize()]}
}

and

"/api/$controller/$id/$property"{
     action = [POST: {"set"+params.property.capitalize()}, GET: {"get"+params.property.capitalize()}]
}

both produced a 404 error.

So I guess Grails only allow this kind of configuration to be static yet. Maybe somebody could dig into the source code to find out later.

coderLMN
  • 3,076
  • 1
  • 21
  • 26