URI, URL, URN: UR Confused

I recently caught myself using URI and URL interchangeably, and realized I couldn’t explain the difference. Never one to pass up a learning opportunity, I did some digging.

URL

URL stands for Uniform Resource Locator. Here are some examples of URLs:

awesomephotos.com/cats/grumpster.png
awesomephotos.com/cats/grumpster.gif
awesomephotos.com/cats/grumpster.jpg
awesomephotos.com/cats/grumpster.psd

The URLs specify a specific type, version or representation of a resource. In this example, they each specify an image type: GIF, PNG, JPG or PSD.

URI

URI stands for Uniform Resource Indicator. A URI is a URL that doesn’t specify a specific representation. In the example above, the URI for all those cat pictures is:

awesomephotos.com/cats/grumpster

A URI indicates what resource is desired, but not a required type/representation of that resource. So a URL is a URI, but a URI is not a URL. Make sense? :)

At this point, you may be wondering to yourself, “Ok, I get it, but how is this distinction useful in the real world?” The answer is:

HTTP Content Negotiation

HTTP Content Negotiation is a mechanism built into the HTTP/1.1 standard that allows for a particular resource to be represented multiple ways, to support multiple clients or use cases.

There are different ways content negotiation is executed, but they all essentially utilize HTTP headers and status codes to communicate about what resources the client wants and the server has available. This is quite extensible, and was intended for many different use cases, including specifying versions of a resource. Cool, right?!

Read the Content negotiation article at MDN for more information.

Um, a real world application, please?

Ok! One example of HTTP content negotiation in the wild is browser support for different image formats. A website can have a GIF and PNG version of an image, and the browsers that support PNG will get PNG, otherwise they can get the GIF image. This is most apparent with IE < 9, where the PNG format is not properly supported.

In fact, If you've ever sent an HTTP request with the 'Content-Type' header, you've engaged in content negotiation! You've essentially told the server, "I want the JSON/XML/HTML representation of this resource."

Wait, wasn't there another acronym?

Ah, yes: URN, which stands for Uniform Resource Name. A URN bears much similarity with a URI, but uses a specific scheme, urn:, instead of http: or https:.

Essentially, URNs were supposed to be a stricter, persistent version of URIs. The standard was eventually deprecated in favor of the more generic URI syntax.

Further Reading

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s