What is the Difference Between URI and URL?

Posted in

What is the Difference Between URI and URL?
sangeeta.gulia

Sangeeta Gulia
Last updated on March 29, 2024

    The World Wide Web (www) consists of a lot of resources and documents. We can access these resources and documents on the web using a unique identifier, called Uniform Resource Identifier (URI). There are two kinds of URI, namely URL and URN. A URN represents the name of a resource and is a location-independent identifier, whereas a URL is a location-dependent identifier and represents the location.

    To understand the difference between URI, URN, and URL, let us take one example. Consider a resource whose name is ‘Henry’ and his location is ‘#169 Rocky River’. He can be identified either with his unique name or the address, and both these unique identities are referred to as URI. A URI can either be the name, location, or both. But a URN can only be the name and URL be the location.

    Therefore, in our example, a URI is either ‘Henry’, ‘#169 Rocky River’, or both together, a URN is ‘Henry’, and a URL is ‘#169 Rocky River’. Suppose we take a URI as only ‘Henry’, which is URN. Using this URI, we cannot identify Henry’s location, and hence, it can’t be a URL. But ‘#169 Rocky River’, which is a URL, can be a URI.

    Therefore, a URI containing only the name of the resource, i.e., URN, can’t be a URL. But all URLs can be URIs, as a URI can be either a resource’s name, location, or both. From the above example, you might have got a brief idea about what exactly URI, URN, and URL are.

    Through this article, we will explore the definition and syntax of a URI and URL, and later, discuss how they differ from each other. So, without any further ado, let’s begin.

    What is a URI?

    URI stands for Uniform Resource Identifier. It is a string identifier used to identify any resource on the internet through its location, name, or both. There are two subsets in URL, namely URL (Uniform Resource Locator) and URN (Uniform Resource Name). As discussed in the above example, if a URI contains only a name, it is not a URL. Some common URI schemes are HTTP, HTTPS, FTP, telnet, LDAP, gopher, news, mailto, etc.

    Syntax of URI

    The syntax of URI consists of five elements, namely scheme, authority, path, query, and fragment. Below is the syntax of URI:

    URI = scheme ":" ["//" authority] path ["?" query] ["#" fragment]
    authority = [userinfo "@"] host [":" port]
    • Scheme: It is a sequence of characters followed by a semicolon (:). It begins with a letter and later involves a combination of letters, plus sign (+), hyphen (-), digits, and period (.). Some famous examples of schemes are http, mailto, https, FTP, IRC, file, and data. It is essential to register a scheme with the Internet Assigned Numbers Authority (IANA), even though non-registered schemes are still in practice. Also, the authority element consists of three different subcomponents, namely userinfo, host, and port.
    • Authority: It is an optional component that follows two forward slashes (//). It consists of three sub-components:
      • userinfo: It is an optional subcomponent consisting of a username and an optional password that follows a colon (:). It is written as ‘username:password’, followed by an at symbol (@).
      • host: It either consists of a registered name or an IP address. Use the dot-decimal notation for IPv4 addresses and brackets ([]) for IPv6 addresses.
      • port: It is also an optional component that follows a colon (:).
    • Path: It is a sequence of path segments, where each segment is separated by a slash (/). A URI has a path that is always defined, though the path may be empty or of zero length. Also, a segment in a path may be empty. If a segment in a path is empty, it results in a double slash (//).
    • Query: Query is again an optional component that follows a question mark (?). It contains a query string of non-hierarchical data.
    • Fragment: It is also an optional component that follows the hash (#) symbol. It consists of a fragment identifier that provides a direction to a secondary resource.

    What is a URL?

    URL stands for Uniform Resource Locator. It is used to find the location of a resource on the web. Therefore, we can say that a URL is a way to access a particular resource or acts as a reference for a specific resource. A resource can be an image, HTML page, CSS documents, etc., and a URL always refers to a unique resource. Informally, we can refer to a URL as a web address. Many web browsers display a web page’s URL in the address bar.

    An example of a URL is:

    https://www.mytext.com/index.html

    where http indicates a protocol, www.mytext.com is a hostname, and index.html is a file name.

    Syntax of URL

    The syntax of an HTML URL conforms to the syntax of a URI. It consists of five components, namely scheme, authority, path, query string, and fragment.

    URI = scheme ":" ["//" authority] path ["?" query] ["#" fragment]
    
    Also, the authority component consists of three different subcomponents, namely userinfo, host, and port, as follows:
    authority = [userinfo "@"] host [":" port]

    URI Vs URL

    The following table highlights all the key differences between URI and URL:

    Uniform Resource Identifier (URI) Uniform Resource Locator (URL)
    URI is an identifier of a resource. URL is a locator of a resource.
    The scheme in URI can be a protocol, name, specification, or anything. The scheme in a URL is only a protocol, like HTTP, HTTPS, LDAP, etc.
    A URI’s primary goal is to identify a resource using its name or location and distinguish it from other resources. A URL’s primary objective is to get the address or location of a resource.
    There are two subsets of URI, namely URL, representing the location of a resource, and URN, representing the name of a resource. URL is a subset of URI.
    An example of URI is http://mytext.com/author/amty.html#posts. In the above example, the URN is mytext.com/author/amty.html#posts, where ‘posts’ is the name of the resource. The URL is http://mytext.com/author/amty.html, as ‘amty.html’ represents the location of a resource. An example of a URL is https://techgeekbuzz.com .
    It is typically used to identify resources and binaries from XML and tag libraries, like JSTL and XSTL. URIs are primarily used for searching web pages on the internet.
    All URIs can’t be URLs; a URI can only contain a resource name using which we cannot find the location of the resource. All URLs are URIs; URIs can contain either the name or location of a resource.

    Conclusion

    From the above discussion, it is clear that the URI is a broader term and is a superset of a URL and URN. It identifies a resource using the name, location, or both. On the other hand, a URL is a subset of URI and identifies the location of a resource.

    This article covered a brief introduction to URI and URL and the key differences between them. There is a subtle difference between URI and URL and occurs only when a URI only specifies a resource’s name. When a URI specifies the location of a resource, URI and URL become the same.

    FAQs


    A URI differentiates between different resources using their name and location. On the other hand, a URL determines the specific location of a resource on the web.

    An email address is an address that determines a particular account on the mail server. The primary difference between a URL and an email address is that an email address has the '@' symbol, while a URL does not.

    A URI identifies a specific resource on the web. Meanwhile, RESTful APIs leverage URIs and HTTP methods (GET/POST/PUT/DELETE) to carry out CRUD operations on web services.

    Leave a Comment on this Post

    0 Comments