URI Template Builder

The UriTemplateBuilder API was added to make it easier to programatically construct URI templates. It’s used like this:

UriTemplate template =
                 .path(var("thing1"),var("explodedThing", true))
                 .fragment(var("prefix", 2))

This will yield the following URL template string:


You can also use the UriTemplateBuilder to build new templates from other templates like so:

        UriTemplate rootTemplate = UriTemplate.fromTemplate("http://example.com/foo{/thing1}");

        UriTemplate template = UriTemplate.buildFromTemplate(rootTemplate)
                .path(var("explodedThing", true))
                .fragment(var("prefix", 2))

        Assert.assertEquals("http://example.com/foo{/thing1}{/explodedThing*}{#prefix:2}", template.getTemplate());

This will get you:


The API is fairly flexible and pretty useful for constructing URI templates. Have a gander at the Java Docs for more details.