Kauri Documentation
4 Kauri conceptsBook Index4.3 The Kauri Runtime: modules

4.2 Routing and resource classes

A RESTful design starts with thinking about the resources you want to expose and their URIs. Kauri thus has very good support for routing requests based on the request URI. You can find more information about routing in the routing chapter.

Kauri provides a flexible routing component. It is configured through a simple Groovy DSL. You do not have to know Groovy for this purpose. Below is a small example, you can probably guess what it does (if not, don't worry, it is all explained in the docs).

builder.router {
  directory(uri: "/resources", root: "module:/resources/")
  resource(uri: "/persons/{id}.html", ofClass: "com.foobar.Person")

The routing will eventually bring the request up to the Java class that will handle it. Such a class, which implements a resource, is called a resource class. In case the URI is not recognized by the system, a 404 Not Found response will be produced.

You can manually implement resource classes based on the Restlet API or the JAX-RS API. That last one is an API defined through the JSR process, and is based on annotations, providing a practical and consice means to implement a resource class. Here is an example to give an idea:

public class PersonResource {

    public KauriRepresentation getPerson(@PathParam("id") String idParam) {

Kauri also includes a component to automatically expose a database model (implemented using JPA) as RESTful resources.

4 Kauri concepts4.3 The Kauri Runtime: modules