URI Paths

The value of the @Controller annotation is a RFC-6570 URI template, so you can embed URI variables within the path using the syntax defined by the URI template specification.

Many other frameworks, including Spring, implement the URI template specification

The actual implementation is handled by the UriMatchTemplate class, which extends UriTemplate.

You can use this class in your applications to build URIs, for example:

Using a UriTemplate

  1. UriMatchTemplate template = UriMatchTemplate.of("/hello/{name}");
  2. assertTrue(template.match("/hello/John").isPresent()); (1)
  3. assertEquals("/hello/John", template.expand( (2)
  4. Collections.singletonMap("name", "John")
  5. ));

Using a UriTemplate

  1. given:
  2. UriMatchTemplate template = UriMatchTemplate.of("/hello/{name}")
  3. expect:
  4. template.match("/hello/John").isPresent() (1)
  5. template.expand(["name": "John"]) == "/hello/John" (2)

Using a UriTemplate

  1. val template = UriMatchTemplate.of("/hello/{name}")
  2. assertTrue(template.match("/hello/John").isPresent) (1)
  3. assertEquals("/hello/John", template.expand(mapOf("name" to "John"))) (2)
1Use the match method to match a path
2Use the expand method to expand a template into a URI

You can use UriTemplate to build paths to include in your responses.