I often end up rolling my own wrapper/extension methods for/around System.Uri and was wondering if anyone knows of a good open source implementation. What I like to do most is parse querystring parameters, build a new query string (this is the key), and replace page names. Got any good ones, or is System.Uri good enough for you?
BradVin's QueryString Builder class is good. Fluent interface and support for encryption.
It's also worth checking out this UrlBuilder class on CodeProject. Similar to System.UriBuilder has better support for working with the QueryString.
Flurl [disclosure: I'm the author] is a fluent URL builder that looks like this:
var url = "http://www.some-api.com"
.AppendPathSegment("endpoint")
.SetQueryParams(new {
api_key = ConfigurationManager.AppSettings["SomeApiKey"],
max_results = 20,
q = "Don't worry, I'll get encoded!"
});
If you happen to be building URLs for the purpose of calling them, Flurl.Http is a companion lib that lets you do HTTP off the fluent chain:
await "https://api.mysite.com"
.AppendPathSegment("person")
.SetQueryParams(new { ap_key = "my-key" })
.WithOAuthBearerToken("MyToken")
.PostJsonAsync(new { first_name = firstName, last_name = lastName });
Get the full package on NuGet:
PM> Install-Package Flurl.Http
or just the stand-alone URL builder:
PM> Install-Package Flurl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With