Skip to content

Latest commit

 

History

History
57 lines (51 loc) · 1.23 KB

README.md

File metadata and controls

57 lines (51 loc) · 1.23 KB

UrlBuilder

UrlBuilder is simple and powerful URL builder.

Get it on NuGet:

PM> Install-Package UrlBuilder

[TestMethod]
public void Test()
{
	var url = new UrlBuilder("http://www.shoutem.local/app");
	url.SetHost("www.shoutem.com").SetScheme(Uri.UriSchemeHttps);
	url.AddPathSegment("test");
	url.SetQueryParam("nid", 123);

	Assert.AreEqual("https://www.shoutem.com/app/test?nid=123", url.ToString());
}

Working with query params:

  • Get query param
var url = new UrlBuilder("http://www.shoutem.com");
if (url.ContainsQueryParam("nid"))
{
	var param = url.GetQueryParam("nid");
}
  • Add and remove query param
url.SetQueryParam("nid", 123);
url.RemoveQueryParam("nid");
  • Add and remove query params
url.SetQueryParams(new Dictionary<string, object> { { "event", 1 }, { "role", "admin" } });
url.RemoveQueryParams(new List<string> { "event", "role" });
  • Append the value if param already exists
url.AppendQueryParam("nid", 321);

Working with path segments:

  • Get and set path
url.SetPath("app/events");
url.GetPath();
  • Add and remove path segment
url.AddPathSegment("test");
url.RemovePathSegment("test");