Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

UriBuilder does not work well with QueryBuilder #647

Closed
NTaylorMullen opened this issue Jun 1, 2016 · 8 comments
Closed

UriBuilder does not work well with QueryBuilder #647

NTaylorMullen opened this issue Jun 1, 2016 · 8 comments

Comments

@NTaylorMullen
Copy link
Member

The UriBuilder class automatically prepends a ? to its Query property which is troublesome when trying to construct a new uri.

For instance:
image

@Tratcher
Copy link
Member

Tratcher commented Jun 2, 2016

What were you going to do with the result?

System.Uri is not well suited for use in HTTP headers. https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNetCore.Http.Extensions/UriHelper.cs works better there.

MVC has other APIs for building urls in HTML bodies.

@NTaylorMullen
Copy link
Member Author

Was going to pass the resulting Uri to an HttpClient. Its post methods accept a Uri so the UriBuilder/QueryBuilder seemed well suited.

@Tratcher
Copy link
Member

Tratcher commented Jun 2, 2016

Ah. UriHelper should work in place of UriBuilder too.

@NTaylorMullen
Copy link
Member Author

Hmm? How would you use UriHelper to do what UriBuilder does? From the class it looks that it's only good for encoding and reading info from a request.

@Tratcher
Copy link
Member

Tratcher commented Jun 3, 2016

            var query = new QueryBuilder()
            {
                { "hello", "world" }
            }.ToQueryString();

            var encoded = UriHelper.Encode("http", new HostString("contoso.com"), query: query);
            var uri = new Uri(encoded, UriKind.Absolute);

            Console.WriteLine(uri.AbsoluteUri);

@NTaylorMullen
Copy link
Member Author

Is that really what we expect users to be doing? The APIs seem very awkward.

@Tratcher
Copy link
Member

Tratcher commented Jun 3, 2016

We never ask users to build a System.Uri, it's only used in client APIs.

@NTaylorMullen
Copy link
Member Author

Talked offline and we both agree that QueryBuilder on its own is actually a really nice API; however, the end-to-end usage of it is horribad 😄. This is primarily due to the UriHelper API.

Therefore, closing this in favor of fixing #573. If you want to also add API to make this consumable from UriBuilder feel free to reopen this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants