grailsurl-mappinggrails-2.5urlmappings.groovy

Grails url mapping doing wrong action call


I'm trying to call the index action and keep calling the count action and i don't know why. This is the code in the urlmapping

group "/api/product",{
    "?"(controller: 'product', action: 'save', method: 'POST')
    "?"(controller: 'product', action: 'index', method: 'GET')
    "/$id?"(controller: 'product', action: 'delete', method: 'DELETE')
    "/$id?"(controller: 'product', action: 'update', method: 'PUT')
    "/$id?"(controller: 'product', action: 'show', method: 'GET')
    "/count?"(controller: 'product', action: 'count', method: 'GET')
}

Solution

  • Try the following mappings:

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