Understanding URLs, URIs, and URNs

Listen to this Post

URL, URI, and URN are related concepts in the context of web and internet technology, often used interchangeably but technically distinct.

URI (Uniform Resource Identifier):

  • A URI is a unique identifier for a resource on the internet, allowing it to be identified and located.
  • URIs combine both locators (URLs) and names (URNs) and serve as a general term for both.
  • They can be either a locator, a name, or both.

URL (Uniform Resource Locator):

  • A URL is a type of URI that is used to locate a resource on a network (usually the internet) by specifying its address.
  • It includes a network location (typically a domain name), a protocol (e.g., HTTP or FTP), and an optional port number.
  • The primary purpose of a URL is to provide a way to retrieve a resource from a server.

Examples of URLs:

– `http://example.com`
– `https://lnkd.in/gM8CW8wF`

URN (Uniform Resource Name):

  • A URN is a type of URI that provides a unique and persistent identifier for a resource without referring to its physical location.
  • URNs are designed to be persistent and last for a long time, typically used for non-interactive resources such as metadata or bibliographic references.
  • They do not rely on a protocol or location to identify the resource.

Example of a URN:

– `urn:isbn:0-520-03893-7` (identifies a book with a specific ISBN)

Key Differences:

  • Location: URL focuses on the location of a resource, while URN focuses on providing a unique identifier.
  • Purpose: URL is used to retrieve a resource, while URN is used for resource identification.
  • Persistence: URNs are designed to be persistent and last for a long time, while URLs may change over time.

You Should Know:

Here are some practical commands and codes related to URLs, URIs, and URNs:

  1. Extracting URLs from a text file using Linux:
    grep -oP '(?<=http://|https://)[^ ]+' file.txt
    

2. Validating a URL using Python:

import re
def validate_url(url):
regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:<a href="?:[A-Z0-9-]{0,61}[A-Z0-9]">A-Z0-9</a>?.)+(?:[A-Z]{2,6}.?|[A-Z0-9-]{2,}.?)|' # domain...
r'localhost|' # localhost...
r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
return re.match(regex, url) is not None

print(validate_url("http://example.com"))
  1. Resolving a URN to a URL using cURL:
    curl -I urn:isbn:0-520-03893-7
    

  2. Listing all URIs in a web page using Python:

    import requests
    from bs4 import BeautifulSoup</p></li>
    </ol>
    
    <p>url = "http://example.com"
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'html.parser')
    
    for link in soup.find_all('a', href=True):
    print(link['href'])
    
    1. Checking if a URL is reachable using Linux:
      curl -Is http://example.com | head -n 1
      

    What Undercode Say:

    Understanding the distinctions between URLs, URIs, and URNs is crucial for anyone working in web development, IT, or cybersecurity. URLs are essential for locating resources on the internet, while URNs provide a persistent way to identify resources without relying on their location. URIs serve as the overarching framework that includes both URLs and URNs.

    In practical terms, knowing how to manipulate and validate these identifiers can help in tasks such as web scraping, data retrieval, and ensuring the integrity of digital resources. The provided commands and code snippets offer a starting point for working with these concepts in real-world scenarios. Whether you’re a developer, a system administrator, or a cybersecurity professional, mastering these fundamentals will enhance your ability to navigate and manage digital resources effectively.

    For further reading, you can visit:

    References:

    Reported By: Ashsau %F0%9D%90%94%F0%9D%90%A7%F0%9D%90%9D%F0%9D%90%9E%F0%9D%90%AB%F0%9D%90%AC%F0%9D%90%AD%F0%9D%90%9A%F0%9D%90%A7%F0%9D%90%9D%F0%9D%90%A2%F0%9D%90%A7%F0%9D%90%A0 – Hackers Feeds
    Extra Hub: Undercode MoN
    Basic Verification: Pass āœ…Featured Image