Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Uri extension methods #489

Closed
tmenier opened this issue Dec 27, 2019 · 0 comments
Closed

System.Uri extension methods #489

tmenier opened this issue Dec 27, 2019 · 0 comments

Comments

@tmenier
Copy link
Owner

tmenier commented Dec 27, 2019

Flurl makes it fairly painless to interoperate with more "native" representations of URLs like System.Uri and String. For example, Flurl.Url has a constructor that takes a string and another that takes a System.Uri, and its ToString and ToUri methods seamlessly convert back. But with strings it takes things a step farther and provides a full set of string extension method that mirror those on Url so you can even skip the tedious step of creating a Url object explicitly.

Lots of .NET libraries (especially those from Microsoft) tend to standardize on System.Uri. So it seems it would be equally useful (or more so) to have all those string extension methods available on System.Uri as well.

For example, if you're working with a library that speaks System.Uri but you'd like to use Flurl's builder methods to modify one, you can do that pretty directly:

uri = uri
    .AppendPathSegment("foo") // a Flurl.Url was created, minus the noise 
    .SetQueryParams(new { x = 1, y = 2 })
    .ToUri(); // convert back

Not to be left out, Flurl.Http will also get new System.Uri extensions to mirror its string extensions:

var thing = await uri.GetJsonAsync<T>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant