Uritemplates for working with formatted URI templates
Pm> Install-package Tavis.uritemplates
Set URI Path Segment
[fact]public void Updatepathparameter () { var url = new UriTemplate ("Http://example.org/{tenant}/customers") . Addparameter ("tenant", "Acmé") . Resolve (); Assert.equal ("http://example.org/acm%C3%A9/customers", url);}
Set QueryString
[fact]public void Shouldresolveuritemplatewithnonstringparameter () { var url = new UriTemplate ("HTTP/ EXAMPLE.ORG/LOCATION{?LAT,LNG} ") . AddParameters (New {lat = 31.464, LNG = 74.386}) . Resolve (); Assert.equal ("http://example.org/location?lat=31.464&lng=74.386", url);}
If the parameter is not set the URL will delete this parameter
[fact]public void Someparametersfromanobject () { var url = new UriTemplate ("http://example.org{/environment}{/ Version}/customers{?active,country} ") . AddParameters (new { Version = "V2", active = "true" }) . Resolve (); Assert.equal ("http://example.org/v2/customers?active=true", url);}
You can pass a list as a parameter
[fact]public void Applyparametersobjectwithalistofints () { var url = new UriTemplate ("http://example.org/ Customers{?ids,order} ") . AddParameters (new { order = "Up", ids = new[] {+,- )}) . Resolve (); Assert.equal ("http://example.org/customers?ids=21,75,21&order=up", url);}
Add a dictionary as a parameter
[fact]public void Applydictionarytoqueryparameters () { var url = new UriTemplate ("http://example.org/foo{?coords* }") . Addparameter ("Coords", New dictionary<string, string> { {"x", "1"}, {"Y", "2"}, }) . Resolve (); Assert.equal ("http://example.org/foo?x=1&y=2", url);}
Package Introduction-Uritemplates (for working with formatted URI templates)