blogsaboutContactPrivacy PolicyTerms & Conditions
Othersuri vs url

Difference Between URI and URL | URI vs URL with Examples

March 3, 2025

13 min read

371 views

Introduction

If you've ever worked with web development, you've likely come across the terms URI vs URL. While they seem similar and are often used interchangeably, they have distinct meanings.

A URI (Uniform Resource Identifier) is a broader term that refers to any string that identifies a resource, whereas a URL (Uniform Resource Locator) is a specific type of URI that not only identifies a resource but also provides its location on the web. For example:

  • A URI could be: mailto:user@example.com (an email address)
  • A URL could be: https://example.com/page (a web address)

Understanding the difference between URI and URL is essential for developers, especially when working with web applications, APIs, and networking. In this article, we'll break down URI vs URL, their key differences, examples, and how they are used in REST APIs.

What is a URI?

A URI (Uniform Resource Identifier) is a string of characters that uniquely identifies a resource on the internet or a local system. It can be a web page, an email address, a file, or even an abstract concept. A URI can be classified into two types:

  1. URL (Uniform Resource Locator): Specifies the location and how to access a resource (e.g., https://devwhirl.com).
  2. URN (Uniform Resource Name): Uniquely names a resource but doesn’t specify how to access it (e.g., urn:isbn:0451450523 for a book's ISBN). ISBN stands for International Standard Book Number, a unique identifier for books.

Real-World URI Examples

  1. Non-URL URIs:

    .js
    1mailto:support@domain.com       (Email identifier)
    2urn:isbn:978-0141036144        (Book identifier)
    3tel:+1-800-123-4567            (Phone number) 

    A URI answers WHAT the resource is, not necessarily WHERE it is. URLs (a subset of URIs) handle the where.

Why Developers Care About URIs

  • API Design: REST APIs use URIs to identify resources (e.g., /users/{id}).
  • Type Safety: In TypeScript, URI types enforce valid formats for paths or endpoints.
  • Configuration: Tools like Docker use URIs to specify image registries (docker://my-image:latest).

What is a URL?

A URL (Uniform Resource Locator) is a specific type of URI that not only identifies a resource but also provides its location and the method to access it. URLs are the web addresses we use every day to visit websites, download files, and access APIs.

A URL consists of multiple components, including the protocol, domain, path, and sometimes a query string or fragment identifier.

URL Structure & Components

A typical URL looks like this:

.js
1https://example.com/products?category=books#reviews

Here's what each part means:

  • Protocol (https://): Defines how to access the resource (HTTP, HTTPS, FTP, etc.).
  • Domain (example.com): The website’s name or IP address.
  • Path (/products): The specific location of the resource on the server.
  • Query String (?category=books): Additional parameters used in web apps and APIs.
  • Fragment (#reviews): Jumps to a specific section of a page.

Examples of URLs:

Website URL:

.js
1https://www.devwhirl.com

API Endpoint URL:

.js
1https://api.example.com/users/1

File Download URL:

.js
1ftp://example.com/files/document.pdf

Key Characteristics of a URL:

  • Identifies and locates a resource.
  • Always includes a scheme/protocol (e.g., http, https, ftp).
  • Every URL is a URI, but not every URI is a URL.

URI vs URL: Key Differences

While both URI (Uniform Resource Identifier) and URL (Uniform Resource Locator) are used to identify resources on the web, they are not the same. Here's a differences between URI and URL:

URI

  • Definition: A URI is a string that identifies a resource, but it doesn't necessarily provide a means of locating it.
  • Identification: Can be used to identify any resource, such as a book, email address, or file.
  • Components: May include just the name or identifier of the resource (can be a URL or URN).
  • Example : mailto:user@example.com (Email address) or urn:isbn:0451450523 (ISBN for a book).
  • Includes Location?: No, a URI doesn’t necessarily provide the location.
  • Access: URI can be either accessed (if it’s a URL) or used as an identifier (if it’s a URN).

URI

  • Definition: A URL is a type of URI that not only identifies a resource but also locates it and specifies how to access it.
  • Identification: Always locates a resource, like a web page or file, and defines how to access it.
  • Components: Always includes the protocol, domain, and path to locate the resource.
  • Example : https://devwhirl.com/blogs (Web page URL).
  • Includes Location?: Yes, a URL always specifies where the resource is located on the web.
  • Access: A URL provides a method for accessing the resource, typically using a protocol like http or ftp.

Summary of Differences:

  • A URL is always a URI, but not all URIs are URLs.
  • A URI can be used to identify a resource (like a name), but a URL goes a step further by specifying how to access that resource.
  • If you are looking for a resource’s location and how to retrieve it, you’re dealing with a URL.
  • If you only need a name or identifier for a resource, you're working with a URI (which could be a URN in some cases).

What is a URN? (URI vs URL vs URN)

A URN (Uniform Resource Name) is another type of URI (Uniform Resource Identifier) that uniquely identifies a resource, but it does not provide the location or the method to access that resource. Essentially, a URN is a name, but not a locator.

While URLs provide the location and method to access a resource, and URIs can be either a URL or URN, a URN is more like a unique identifier that doesn't rely on any specific location or protocol to access the resource. It’s meant to be persistent and remain valid over time, even if the resource moves or changes locations.

URN Structure & Examples

A URN follows a specific syntax and is typically structured like this:

.js
1urn:<namespace identifier>:<namespace-specific string>
  • Namespace Identifier (NID): A short string that identifies the naming system or category (e.g., isbn, issn).
  • Namespace-Specific String (NSS): A unique identifier for the resource within the specified namespace (e.g., a book’s ISBN number).

Examples of URNs:

  • ISBN (International Standard Book Number):
    .js
    1urn:isbn:0451450523
    This URN uniquely identifies a book by its ISBN, but it doesn't specify where to access it.
  • DOI (Digital Object Identifier):
    .js
    1urn:doi:10.1000/182
    This URN identifies a research paper or academic publication by its DOI, without revealing where to retrieve it.

Key Characteristics of a URN:

  • Persistent: A URN is meant to be a permanent, that remains valid even if the resource changes location.
  • No Location: Unlike a URL, a URN does not specify how to access the resource; it only identifies it uniquely.
  • Global Scope: URNs are often used for things like ISBNs, DOIs, and other global identifiers that need to remain consistent across different systems.

URN vs URI vs URL

  • URI: A generic identifier that can be either a URN or a URL.
  • URL: A URI that specifies both the location and method to access the resource.
  • URN: A URI that uniquely identifies a resource without providing its location or how to access it.

In short, A URN is a type of URI that focuses on naming a resource rather than locating it. While URLs are used to access web resources, URNs provide a permanent, location-independent way to identify things like books, documents, or other globally unique items.

URI vs URL in REST API

In the context of REST (Representational State Transfer) APIs, URI and URL play an essential role in how resources are identified and accessed. While both URI and URL are used to identify resources on the web, their roles and usage in RESTful systems can vary slightly. Here’s how they are used in REST APIs:

URI in REST API

In a REST API, a URI is the unique identifier for a resource. It’s used to represent an object or a collection of objects that your API can interact with. However, while a URI identifies the resource, it doesn’t necessarily tell you how to retrieve or access the resource. A URI can be a URL or a URN, but in the context of REST, we’re typically concerned with the URL form of a URI. For example:

  • URI could represent a user resource in an API:
    .js
    1/users/{id}
    This URI identifies a user resource with a specific id, but it doesn’t tell you how to retrieve that user.

URL in REST API

A URL is a specific form of URI that not only identifies a resource but also provides the location of that resource and how to access it, typically using an HTTP method like GET, POST, PUT, or DELETE.

In REST APIs, URLs are used to define endpoints that clients can send HTTP requests to. These URLs will often consist of a base URL (the root address of the API), followed by path segments that specify the exact resource and any associated actions or parameters.

URL Structure in REST API:

A typical REST API URL might look like this:

.js
1https://api.example.com/users/1

Where:

  • Protocol: https:// (defines how the data will be transferred).
  • Domain: api.example.com (the server where the API is hosted).
  • Path: /users/1 (the resource identifier — in this case, the user with id=1).

The URL is used to retrieve or manipulate that resource, often with specific HTTP methods:

  • GET https://api.example.com/users/1: Retrieve user data.
  • POST https://api.example.com/users: Create a new user.
  • PUT https://api.example.com/users/1: Update user data.
  • DELETE https://api.example.com/users/1: Delete the user.

Both** URI vs URL** play important roles in REST APIs, but they serve slightly different purposes. A URI simply identifies a resource, while a URL is a specific type of URI that not only identifies the resource but also tells you where it’s located and how to access it.

Frequently Asked Questions

  • Q: What is the main difference between URI and URL?

    A: A URI (Uniform Resource Identifier) is a broad term that refers to any string that uniquely identifies a resource, but it doesn't necessarily provide a way to locate or access it. A URL (Uniform Resource Locator), on the other hand, is a specific type of URI that not only identifies a resource but also provides the location and method to access it.

  • Q: Can a URI be a URL?

    A: Yes, a URI can be a URL. In fact, every URL is a URI, but not every URI is a URL. A URL is a specific form of URI that includes the location and protocol needed to access the resource, whereas a URI can also be a URN (Uniform Resource Name) that simply identifies a resource without giving any location details.

  • Q: How are URIs used in REST APIs?

    A: In REST APIs, URIs are used to identify resources. They define endpoints for actions like retrieving, creating, updating, or deleting data. For example, a URI in a REST API could be /users/{id}, which identifies the user resource with a specific id, while the URL would specify how to access it, e.g., https://api.example.com/users/1.

  • Q: Is Every URL a URI?

    A: Yes, every URL is a URI. A URL is a specific type of URI that not only identifies a resource but also provides the means to locate it using a protocol like HTTP or FTP. However, not every URI is a URL, since some URIs, like URNs, only identify resources without providing a location.

Conclusion

In conclusion, understanding the difference between URI and URL is key for anyone working with web development or APIs.

knowing the difference between URI and URL helps you better understand how resources are identified and accessed, especially when working with web resources or APIs. With this knowledge, you’ll be better prepared for web development and API design.

If you found this blog helpful, feel free to share it with others who may benefit from it!

Share this article

On this page: