Josh Gibson
Josh Gibson

Reputation: 22968

Example of a URI that isn't a URL?

It's been explained to me numerous times that all URLs are URIs but not all URIs are URLs. Can anyone give an example of something that is a URI but is not a URL?

Upvotes: 52

Views: 42696

Answers (7)

Francisco
Francisco

Reputation: 101

An example of a URI that is neither a URL nor a URN would be a data URI such as: data:,Hello%20World It is not a URL nor a URN because the URI contains the data. It neither names it, nor tells you how to locate it over the network.

Taken from here: What is the difference between a URI and a URL?

I believe the answer from TofuBeer (most voted so far) is wrong.

Upvotes: 10

bendewey
bendewey

Reputation: 40265

A Uniform Resource Name (URN) is a URI that identifies a resource by name in a particular namespace. A URN can be used to talk about a resource without implying its location or how to access it. For example, the URN urn:isbn:0-395-36341-1 is a URI

From: Wikipedia: Uniform Resource Identifier

Upvotes: 5

zak23
zak23

Reputation: 3418

urn:isbn:0451450523

Source: Uniform Resource Name - Wikipedia

Upvotes: 13

Dmitriy Popov
Dmitriy Popov

Reputation: 2360

To test the exception failing in my unit test (covering URI ←→ URL conversion in Java), I use the following examples:

  • "_ " — Non-valid URI from String
  • "data://valid-uri" — valid URI, but not valid, malformed URL (MalformedURLException thrown from URI#toURL).
  • "valid-uri" — valid URI, but not valid, non-absolute URL (IllegalArgumentException thrown from URI#toURL).
  • "http:// _" — valid URL, but not valid, malformed URI (URISyntaxException thrown from URL#toURI).

It may be not an RFC-spec-perfect answer, but these are working examples for Java.

Upvotes: 3

Jeffrey Hantin
Jeffrey Hantin

Reputation: 36534

A common case would be a URN, which is a URI of the format urn:namespace-id:resource-id. Per Wikipedia:

Defined in 1997 in RFC 2141, URNs were intended to serve as persistent, location-independent identifiers, allowing the simple mapping of namespaces into a single URN namespace. The existence of such a URI does not imply availability of the identified resource, but such URIs are required to remain globally unique and persistent, even when the resource ceases to exist or becomes unavailable.

Both styles of resource reference (URL and URN) were later combined under the concept of the URI, but they remain recognized as serving distinct purposes (emphasis mine):

A Uniform Resource Name (URN) can be compared to a person's name, while a Uniform Resource Locator (URL) can be compared to their street address. In other words, a URN identifies an item and a URL provides a method for finding it.

Upvotes: 3

Blake Taylor
Blake Taylor

Reputation: 9341

XML Schemas are often identified with a URI and while they may be formatted similarly there is no guarantee that there is anything there because it is not a URL.

The ability to identify the correct XML schema is necessary if you must validate an XML file. A means of identification must be shared between the content and the schema authors before successful validation can mean anything useful. URIs fill this need as good as anything else. Keep in mind that the schema is not necessarily needed in order to make use of the XML file. Therefore it does not need to be universal locatable or available, it simply needs to be identifiable. The semantics of a URI avoid the implication that the resource must be located "here", as would be the case with a URL, and with good reason. Such a detail is irrelevant to the task of identification.

Schema publishers will often base the URI off of a URL which they own. I can imagine there are many reason for doing this, but for one, it helps avoid naming conflicts without an intermediary. When using such a convention it is hard to resist hosting the definition at the location the URI would point to if it where a URL. While by know means necessary, I believe doing so marks an appreciated effort, and is an example of good information architecture, but this fact remains unrelated to needs filled by a URI.

Upvotes: 5

TofuBeer
TofuBeer

Reputation: 61546

Example stolen from here (where there is also a description of the differences):

URL     http://www.pierobon.org/iis/review1.htm
URN     www.pierobon.org/iis/review1.htm#one
URI     http://www.pierobon.org/iis/review1.htm.html#one

Upvotes: 24

Related Questions