0
votes

I'm implementing a rest service in grails so I created a controller:

class LoaderController {

  def index = { }

  def save = {

    String input = params.er3f
    render 'OK'

  }
}

And added the following in UrlMappings:

"/loader/$id?" (controller:loader) {
   action = [GET:"save"]
}

When I run http://localhost:8080/MyApp/loader?er3f=12345678, I get a 404 and description The requested resource (/MyApp/WEB-INF/grails-app/views/loader/index.jsp) is not available.

But when I run http://localhost:8080/MyApp/loader/save?er3f=12345678 works OK.

What's wrong with my UrlMappings?

1

1 Answers

3
votes

For starters you're not using the mapping you defined. You specify an id parameter but pass er3f and don't use / syntax but put it in the querystring with ? - calling http://localhost:8080/MyApp/loader/12345678 would use the syntax.

But you're also mixing two different approaches in the mapping itself, so it's not firing. You can use a Map and specify the action and controller in parens, or use a Closure and specify them there, but you can't mix them.

And finally, you've specified an id parameter but are looking for an er3f parameter in the controller, so that will always be null.

This is the mapping you want:

"/loader/$er3f?" {
   action = [GET:"save"]
   controller = 'loader'
}