0

I'm using Grails v3.2.9

In official documentation I found the following for mapping to http methods:

static mappings = {
   "/product/$id"(controller:"product", action: "update", method: "PUT")
}

But this is not enough. What I need is to have one mapping which maps to different actions(in the same controller) based on HTTP method.

Any idea ?

Suren Aznauryan
  • 984
  • 10
  • 24

2 Answers2

2

Add URLMappings like --

"/product/api/v2/book" (controller: 'book') {
    action = [GET: 'show', POST: 'update']
}

Also, it is good to add method constraint in controller --

  static allowedMethods = [show: 'GET', update: 'POST']
MKB
  • 7,587
  • 9
  • 45
  • 71
0

Alternatively, if you follow the method naming convention for REST controllers... you could get away with:

"/product/$id" (resources:'product')

Here's some good info: http://mrhaki.blogspot.com/2013/11/grails-goodness-customize-resource.html

billjamesdev
  • 14,554
  • 6
  • 53
  • 76