1

When I create the grails 2.2.4 app below, I see responses to POST /options/somewhere but not to OPTIONS /options/somewhere.

Is there some way to invoke a controller action on OPTIONS requests?


App where POST works and OPTIONS doesn't:

$ grails create-app options
$ grails create-controller api

UrlMappings.groovy:

class UrlMappings {
  static mappings = {
    "/somewhere" (controller: "api", parseRequest: true) {
      action = [OPTIONS: "getOptions", POST: "saveStuff"]
    } 
  } 
}

ApiController.groovy:

package options

class ApiController {
    def getOptions() {
      render("Your options await.")
    }
    def saveStuff() {
      render("Stuff saved.")
    }
}
Bosh
  • 8,138
  • 11
  • 51
  • 77

1 Answers1

1

Try this code:

 "/somewhere" (controller: "api", parseRequest: true) { //controller name begins with a lowercase letter
        action = [OPTIONS: "getOptions", POST: "saveStuff"]
    }

I use grails 2.0.3 and it do not work as I expected. But should work for latest grails version (2.3). Pls see related bug.

rxn1d
  • 1,236
  • 6
  • 18
  • It should. I need more information about your application. Can you provide your controller code and actual request url ? – rxn1d Sep 12 '13 at 16:43
  • I've updated my question to make this really explicit. Can you confirm that this actually works for you? – Bosh Sep 12 '13 at 17:48
  • I ll try as soon as i get to my job=) – rxn1d Sep 12 '13 at 19:15