Javatpoint Logo
Javatpoint Logo

URI vs URL | Difference between URI and URL

URI vs URL

While surfing the internet or checking any website, you may have encountered the words "URI" and "URL" multiple times. These are the two important concepts of web and are mostly used interchangeably. But they are not the same as each other; the main difference between URI and URL is that URI can represent both URL and URN of a resource simultaneously, whereas URL can only specify the address of the resource on the internet. In this topic, we will see URI and URL individually and how both can be differentiated from each other.

What is URI?

A URI or Uniform Resource Identifier is a string identifier that refers to a resource on the internet. It is a string of characters that is used to identify any resource on the internet using location, name, or both.

A URI has two subsets; URL (Uniform Resource Locator) and URN (Uniform Resource Number). If it contains only a name, it means it is not a URL. Instead of directly URI, we mostly see the URL and URN in the real world.

URI vs URL

A URI contains scheme, authority, path, query, and a fragment. Some most common URI schemes are HTTP, HTTPs, ftp, Idap, telnet, etc.

Syntax of URI

The Syntax of URI is given below:

  • Scheme: The first component of URI is scheme that contain a sequence of characters that can be any combination of letter, digit, plus sign, or hyphen (_), which is followed by a colon (:). The popular schemes are http, file, ftp, data, and irc. The schemes should be registered with IANA.
  • Authority: The authority component is optional and preceded by two slashes (//). It contains three sub-components:
    • userinfo: It may contain a username and an optional password separated by a colon. The sub-component is followed by the @ symbol.
    • host: It contains either a registered name or an IP address. The IP address must be enclosed within [] brackets.
    • Port: Optional
  • Path: It consists of a sequence of path segments separated by a slash(/). The URI always specifies it; however, the specified path may be empty or of 0 lengths.
  • Query: It is an optional component, which is preceded by a question mark(?). It contains a query string of non-hierarchical data.
  • Fragment: It is also an optional component, preceded by a hash(#) symbol. It consists of a fragment identifier that provides direction to a secondary resource.

Some examples of URI

  1. mailto:hey.Doe@example.com
  2. news:comp.infosystems.www.servers.unix
  3. urn:oasis:names:specification:docbook:dtd:xml:4.1.2

What is the URL?

A URL or Uniform Resource Locator is used to find the location of the resource on the web. It is a reference for a resource and a way to access that resource. A URL always shows a unique resource, and it can be an HTML page, a CSS document, an image, etc.

A URL uses a protocol for accessing the resource, which can be HTTP, HTTPS, FTP, etc.

It is mainly referred to as the address of the website, which a user can find in their address bars. An example of an URL is given below:

URI vs URL

Note: All URLs can be URIs, but all URIs cannot be URLs. It is because a URI contains both URL and URN and represent URL or URN, or both.

URI vs URL

Syntax of URL

Each HTTP URL follow the syntax of its generic URI. Hence the syntax of the URL is also similar to the syntax of URI. It is given below:

The above URL is made up of the following components:

  • Scheme: The URL's first component is a scheme, which represents a protocol that a browser must need to use to request the resource. The commonly used protocols for websites are HTTP or HTTPS.
  • Authority: The authority includes two sub-components, domain name and Port, separated by a colon. The domain name can be anything, the registered name of the resource like javatpoint.com, and port is the technical gate to access the resource on a webserver. The port number 80 is used for HTTP and 443 is used for HTTPS.
  • Path: The path indicates the complete path to the resource on the webserver. It can be like /software/htp/index.html.
  • Query String: It is the string that contains the name and value pair. If it is used in a URL, it follows the path component and gives the information. Such as "?key1=value1&key2=value2".
  • Fragment: It is also an optional component, preceded by a hash(#) symbol. It consists of a fragment identifier that provides direction to a secondary resource.

Key differences between URI and URL

  • URI contains both URL and URN to identify the name and location or both of a resource; in contrast, URL is a subset of URI and only identifies the location of the resource.
  • The example of URI is urn:isbn:0-476-27557-4, whereas the example of URL, is https://google.com.
  • The URI can be used to find resources in HTML, XML, and other files also, whereas, URL can only be used to locate a web page.
  • Each URL can be a URI, whereas all URIs cannot always be URLs.

Difference chart between URI and URL

URI URL
URI is an acronym for Uniform Resource Identifier. URL is an acronym for Uniform Resource Locator.
URI contains two subsets, URN, which tell the name, and URL, which tells the location. URL is the subset of URI, which tells the only location of the resource.
All URIs cannot be URLs, as they can tell either name or location. All URLs are URIs, as every URL can only contain the location.
A URI aims to identify a resource and differentiate it from other resources by using the name of the resource or location of the resource. A URL aims to find the location or address of a resource on the web.
An example of a URI can be ISBN 0-486-35557-4. An example of an URL is https://www.javatpoint.com.
It is commonly used in XML and tag library files such as JSTL and XSTL to identify the resources and binaries. It is mainly used to search the webpages on the internet.
The URI scheme can be protocol, designation, specification, or anything. The scheme of URL is usually a protocol such as HTTP, HTTPS, FTP, etc.

Conclusion

As per the above discussion, we can now differentiate between URI and URL. A URI is a sequence of characters that identifies a web resource by location, name, or both available on the internet. Whereas, URL is a sequence of characters that only identifies the location of a resource available on the internet.


Next TopicIMAP vs. POP3




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA