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
UriMatchTemplate template = UriMatchTemplate.of("/hello/{name}");
assertTrue(template.match("/hello/John").isPresent()); (1)
assertEquals("/hello/John", template.expand( (2)
Collections.singletonMap("name", "John")
));
Using a UriTemplate
given:
UriMatchTemplate template = UriMatchTemplate.of("/hello/{name}")
expect:
template.match("/hello/John").isPresent() (1)
template.expand(["name": "John"]) == "/hello/John" (2)
Using a UriTemplate
val template = UriMatchTemplate.of("/hello/{name}")
assertTrue(template.match("/hello/John").isPresent) (1)
assertEquals("/hello/John", template.expand(mapOf("name" to "John"))) (2)
1 | The match method can be used to match a path |
2 | The 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.