URI Paths

The value of the @Controller annotation is a RFC-6570 URI template you can therefore 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 explicitly within your application 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)
1The match method can be used to match a path
2The expand method can be used to expand a template into a URI.

If you have a requirement to build paths to include in your responses you can use UriTemplate to do so.