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
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 | Use the match method to match a path |
2 | Use the expand method to expand a template into a URI |
You can use UriTemplate to build paths to include in your responses.