Kauri Documentation
 PreviousHomeNext 
5.2 Prototyping: how it worksBook Index6.2 The full picture: how a request is routed

6 Routing

6.1 What is routing?

In Kauri, routing means the problem of mapping an incoming request to a resource class.

Routing is usually done based on the request URI, in particular its path component.

   http://kauriproject.org/documentation/tutorial.html?foo=bar&foo2=bar2
   <--> <----------------><--------------------------><---------------->
  scheme    authority              path                  query string

If you are familiar with other web-frameworks supporting configurable routing, you are probably wondering how the routing is configured in Kauri. For completeness, you should know there are multiple levels of routing (see next section), but the most interesting one is how routing is done within a module. For this, Kauri provides a standard routing infrastructure which is configured with a syntax like this:

builder.router {
    resource(uri: "/user/{name}", ofClass: "mystuff.UserResource")
    resource(uri: "/order/{orderId}", ofClass: "mystuff.OrderResource")
}

The syntax of this file is Groovy using the Groovy Builder convention. The uri patterns are defined using URI template syntax, in which the parts in brackets {} represent wildcards.

This is a very basic example, there are lots of other possibilities described later on.

 PreviousHomeNext 
5.2 Prototyping: how it works6.2 The full picture: how a request is routed