////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

To create a simple mapping simply use a relative URL as the method name and specify named parameters for the controller and action to map to:

[source,groovy]
----
"/product"(controller: "product", action: "list")
----

In this case we've mapped the URL `/product` to the `list` action of the `ProductController`. Omit the action definition to map to the default action of the controller:

[source,groovy]
----
"/product"(controller: "product")
----

An alternative syntax is to assign the controller and action to use within a block passed to the method:

[source,groovy]
----
"/product" {
    controller = "product"
    action = "list"
}
----

Which syntax you use is largely dependent on personal preference. 

If you have mappings that all fall under a particular path you can group mappings with the `group` method:

[source,groovy]
----
group "/product", {
    "/apple"(controller:"product", id:"apple")
    "/htc"(controller:"product", id:"htc")
}
----

You can also create nested `group` url mappings:

[source,groovy]
----
group "/store", {
    group "/product", {
        "/$id"(controller:"product")
    }
}
----

==== Group Defaults

Groups can specify default mapping parameters that are inherited by all child mappings. This avoids repeating the same `controller`, `namespace`, or `plugin` on every mapping within the group:

[source,groovy]
----
group "/internal/community", namespace: 'community', controller: 'communitySearch', {
    "/search"(action: 'internalSearch')
    "/find-user"(action: 'internalFindUser')
    "/user-activity"(action: 'internalUserActivity')
}
----

This is equivalent to specifying `namespace` and `controller` on each mapping individually. Child mappings can override any default by specifying the parameter explicitly:

[source,groovy]
----
group "/api", namespace: 'api', controller: 'defaultCtrl', {
    "/special"(controller: 'specialCtrl', action: 'handle')  // overrides controller
    "/normal"(action: 'index')                                // inherits controller
}
----

Nested groups merge defaults — inner groups inherit and can extend or override outer group defaults:

[source,groovy]
----
group "/community", namespace: 'community', {
    group "/topics", controller: 'topic', {
        "/gallery"(action: 'gallery')   // inherits namespace and controller
        "/create"(action: 'create')
    }
    group "/members", controller: 'member', {
        "/index"(action: 'index')       // inherits namespace, different controller
    }
}
----

The supported default parameters are: `controller`, `action`, `namespace`, `plugin`, `view`, and `method`.

To rewrite one URI onto another explicit URI (rather than a controller/action pair) do something like this:

[source,groovy]
----
"/hello"(uri: "/hello.dispatch")
----

Rewriting specific URIs is often useful when integrating with other frameworks.
