.NET implementation of the URI template spec (RFC6570):
- Supports up to level 4 template expressions
- Fluent API for manipulating URI templates
- Strong validation and error reporting
- Precompiled URI templates
- Partial resolve of URI templates
- It is passes all tests defined by the uritemplate-test suite.
- Targets .NET Standard 2.0
Install via NuGet package
Resolve a URI template:
var template = new UriTemplate("http://example.org/{area}/news{?type,count}");
var uri = template.Resolve(new Dictionary<string, object>
{
{ "area", "world" },
{ "type", "actual" },
{ "count", "10" }
});
Assert.AreEqual("http://example.org/world/news?type=actual&count=10", uri);
Resolve a URI template using fluent interface:
var template = new UriTemplate("http://example.org/{area}/news{?type}");
var uri = template.GetResolver()
.Bind("area", "world")
.Bind("type", new string[] { "it", "music", "art" } )
.Resolve();
Assert.AreEqual("http://example.org/world/news?type=it,music,art", uri);
Construct a URI template:
var template = new UriTemplateBuilder()
.Literal("http://example.org/")
.Simple(new VarSpec("area"))
.Literal("/last-news")
.Query("type", new VarSpec("count"))
.Build();
Assert.AreEqual("http://example.org/{area}/news{?type,count}", template.ToString());
Partial resolve a URI template:
var template = new UriTemplate("http://example.org/{area}/news{?type,count}");
var partiallyResolved = template.GetResolver().Bind("count", "10").ResolveTemplate();
Assert.AreEqual("http://example.org/{area}/news?count=10{&type}", partiallyResolved.ToString());
NB! Partial resolve of expressions default
, reserved
and fragment
is not possible for multiple variables.
Copyright 2013 Pavel Shkarin