Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does .NET have a UriBuilder as opposed to a UrlBuilder?

OK, so having digested such excellent answers as this one difference between URLs and URIs, I think I now understand the distinction between the two.

What I now don't understand is why the .NET Framework has a UriBuilder class, which - as far as I can tell - only works on URIs which are resource locators and should therefore properly be called a UrlBuilder.

Can someone give me an example of UriBuilder being used to build a URI which is not a resource locator? Or some rationale for this decision in the design of the .NET framework?

like image 952
Dylan Beattie Avatar asked Jul 09 '12 10:07

Dylan Beattie


People also ask

What is the difference between a URL and a URI?

URI identifies a resource and differentiates it from others by using a name, location, or both. URL identifies the web address or location of a unique resource. URI contains components like a scheme, authority, path, and query. URL has similar components to a URI, but its authority consists of a domain name and port.

What is URI builder?

Builder is a Builder type that store a Builder in it. Uri is a Built type that store an already built URI in it.


1 Answers

When you think about it, a UriBuilder is more powerful and broader than a URL Builder. Since every URL is a URI, a UriBuilder is inherently a URL Builder.

So basically the question is when could you use a UriBuilder for a non-URL URI. Well, I guess the best example would be for a URN (since URLs and URNs are basically locators and names -- the two classifications of URIs). A URN could be used, for example, to build a uuid (i.e. urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66) or an ISBN (i.e. ISBN 0-486-27557-4). These URNs don't contain location information that points to a resource like URLs do, they just contain names or ids. A UriBuilder would be able to build not just URLs (which point to a resource), but it would also be able to build URNs. If you look at the Uri.Scheme property, you will see uuid in the list of possible schemes for a Uri.

Also, .NET does technically have a UrlBuilder class.

like image 84
Michael Frederick Avatar answered Oct 13 '22 14:10

Michael Frederick