This tutorial provides a comprehensive understanding of Uniform Resource Locator (URL) and Uniform Resource Name (URN) with examples:
The digital world today is very connected and is changing and progressing at a very rapid speed. Internet is a global network of billions of computers and other electronic devices. The Internet has made it possible to access information, communicate with anyone in the world, and do many more things.
The core to this fascinating progress is the information available and the ease of accessing and using the information. Uniform Resource Identifier identifies an object on the Internet. Resource’s location or name or both and the protocol for communication are the keys to URIs identification mechanism.
Uniform Resource Locator (URL) establishes the identity of the object by giving the location and the protocol or the mechanism to retrieve it. Uniform Resource Name (URN) identifies the object by name. Hence URN and URL are subsets of URI and help in retrieving the objects on the Internet easily.
Table of Contents:
Understanding URL And URN
Recommended Reading =>> URL Vs URI – Key Differences Between URL And URI
URL Vs URN:
Definition Of URL And URN
Uniform Resource Locator (URL) is a string of characters that refers to the address of the resource on the Internet. URL assists in reaching the location where the object can be found. Basically, they are the web address or location of the files, videos, documents, images, web pages, etc. that have been published and shared on the Internet.
URL also provides the approach scheme or protocol to reach the location and retrieve the information.
Uniform Resource Name (URN) is a string of characters that gives the name of the resource. Like in real life, two objects on the Internet also can have the same name. URN gives a unique identity of a resource within a defined area or namespace.
The combination of URL and URN gives the resource a unique identity.
URL Components
Let us understand the URL components below:
Syntax:
scheme/protocol://host name[:port number] [/path][/query_string][/#fragment]
#1) URL Scheme/protocol: It is the identifier that indicates the name of the protocol to be used to retrieve or fetch the resource. It is the communication to be used between the client browser and the host server.
Listed below are some common and most used protocols:
- HTTP (Hypertext Transfer Protocol)
- HTTPS (HTTP Secure) for web resources
- mail to for email addresses
- FTP for files on a File Transfer Protocol
- telnet for a session to access remote computers
#2) Host/Domain Name: It is the name or the IP address where the resource is located. The domain name in the URL is case-sensitive.
#3) Port: The port number is optional. It indicates the port number of the host on which the site is hosted. Sometimes a host can be serving multiple applications, email servers, etc. In such cases, when there are multiple applications hosted, it becomes important to give the port number to connect and reach the specified resource.
Generally, it defaults to 80 (for HTTP) or 443 (for HTTPS), if it is not mentioned.
#4) Path: It is the pathname where the resource is located on the domain mentioned.
#5) Resource fragment: It is optional and used if the resource has to be set at a particular section of the web page, like the top of the page or bottom of the page, or a specific section of the page. Browsers search for the fragment tag anchor in the web page’s Html code and scroll the website to it.
https://example.com:443/# Rule4.4.3
This will navigate to the home page of example.com but not to the top but to the section where Rule4.4.3 is detailed.
#6) Query String: It is the feature that allows a query to be executed and the page is loaded as per the result of the query. The main components that follow the ‘?’ are the parameter key and the value of the parameter that needs to be searched follows the ‘=’ sign. Multiple parameter keys can be appended with the ‘&’ separator.
The URL string needs to be URL Encoded, i.e. there are certain rules that need to be followed.
Few examples mentioned below:
- Text URL Encoded
- Hello World Hello+World
- What? What%3F
- Equal sign = Equal+sign%3D
Many URL encoders and decoders are available and can be used for building the query string properly.
Example: http://www.softwaretestinghelp.com/software-testing-qa-videos?course=python
If the resource or the course detail file to be loaded depends on the course selected, then the query string to load the course material will have a filter for the course selected.
URL Types
The structure of the URL helps the search engines to reach the desired location and access the identified resource. Absolute and relative URLs are both ways to structure a site and link to its resources. Absolute URLs are known for providing better security and SEO performance. Relative URLs are website developer-friendly, as they are easier to use and faster.
There are two types of URLs:
#1) Absolute
A URL with a complete address of the resource is called an Absolute URL. The address points to the protocol, domain, then the path, and the name of the resource i.e. protocol://domain/path/resource name.
http://www.softwaretestinghelp.org/wp-content/uploads/2014/04/day-2.jpg
Some advantages of Absolute URLs are as follows:
- Provides better security by making it difficult to clone the site.
- It stops duplication of content and helps search engines to fetch one webpage instead of multiple versions of the same webpage. Relative URL leads to creating multiple versions of the same webpage by search engine crawling during crawling.
- Assists in indexing the site by search engine crawlers and facilitating quick search.
#2) Relative
As the term relative suggests, the relative URL gives the address of the resource from the current location. It does not give the resource’s absolute address. So, the prerequisite for relative URL is that we need to be at the website and only then it can point to objects in the same website using relative URL.
The search for the resource using just the relative URL in the browser will not open the desired object.
Example <a href = “/doc1.html”> will open the document only if the user is already in the website.
Some advantages of Relative URLs are as follows:
- Assists and makes coding easier and faster for website developers by giving shorter URL names.
- During live and development stage, the multiple versions and different domains need not result in changing multiple URLs in the code. The one change will be to load the latest or the concerned version of the webpage, and the use of relative URL throughout the code remains unchanged.
URN Syntax
URN syntax:
urn:<nid>:<nss></nss></nid>
Each URN has three components:
- URNs scheme specification.
- namespace identifier – NID. NID should be registered in IANA (The Internet Assigned Numbers Authority). IANA regulates and monitors the domain names, IP addresses, and protocol parameter identifiers that are used by Internet standards. IANA is an administrative function of the Internet.
- NSS – namespace-specific string. This identifies the specific resource.
Listed below are some NID numbers of specific Name space:
NID | Name space | Details |
---|---|---|
Isbn | International Standard. Books Number | A unique identifier for books |
Issn | International Standard Serial Number | A unique identifier for periodicals |
Nbn | National Bibliography Number | A country-specific unique identifier for some national libraries |
Uuid | Universally Unique Identifier | A unique information identifier within a computer system. |
Isan | International Standard Audiovisual Number | A unique number for audio-visual works like films |
Example: urn:isbn:00939963
This is basically a book with the specified ISBN no.
URL And URN Examples
#1) URL using IP Address instead of the domain name: http://123.222.11.444 which is the IP address of webpage mypage.com
#2) URL protocol FTP used for sharing files on the Internet. The server and client can transfer files over the Internet. File upload to a server and download from a server to the client is made possible.
Example: ftp://www.softwaretestinghelp.com/course.jpg
#3) URL protocol mailto. This is the type of HTML link to the default mail client setup in the m/c to send an e-mail. Mailto link will open a new mail window when the request is hit.
Example: mailto:Name1@softwaretestinghelp.com
The below image shows the URL with mailto protocol:
#4) Uniform Resource Locator using file port: https://example.com:443
#5) Also by using file path: This will navigate to the jpg image which is located at the website as shown below for example 2.
Example 1: http:// www.softwaretestinghelp.org/wp-content/uploads/2014/04/day-2.jpg
Example 2: https://www.softwaretestinghelp.com/wp-content/qa/uploads/2021/02/Are-Your-Developers-As-Good-At-Testing-As-They-Think-They-Are_.png
The below image shows a URL with a path navigating to the specific resource of a web page:
#6) Uniform Resource Locator using fragment: http://www.softwaretestinghelp.org/software-testing-qa-videos/#site-bottom
This will navigate to the home page but not to the top but to the bottom section as shown below i.e. the its fragment is navigating to the specific section of a web page.
#7) URL using query string: https://www.softwaretestinghelp.com/?s=automation
This URL will fetch all the pages, which result in the key search parameter as ‘automation’
The below example shows URL search string – navigating to a page with the ‘Automation’ string
#8) URL using query string with one search parameter: http://www.Interviewprep.com/resources/?jobprofile=testing. The parameter key is jobprofile, and the value is testing. This will navigate the section showing all the interview questions for jobprofile – testing.
#9) Uniform Resource Locator using query string with multiple search parameters: http://www.Interviewprep.com/resources/?jobprofile=testing&speciality=insurance
Here the page should navigate to the section showing all the interview questions for jobprofile – testing for the specific domain Insurance.
#10) URN using standard namespace nbn – for national library
urn:nbn:de:101:15-2019072802401757702913
In the above example, there are additional strings ‘de’ which is the country code for Germany and is an established standard. Next, a subnamespace identifier is used (SNID) which stands for German National library. Then the last component is the unique number.
How Do URIs Work
URI’s (URL + URN) main function is to facilitate information flow between a client and a server. The diagram below explains data being requested by the client to a specific server and server responding and sending the information to the client.
URI Request processing flow and response:
File Transfer Protocol (FTP) is another key purpose served by a Uniform Resource Locator. It facilitates the transfer of files, download, and upload of files between computer systems and between servers in a different location on the Internet.
File transfer Protocol basic information flow:
Frequently Asked Questions
Q #1) How to find the Uniform Resource Locator of a page of a website?
Answer: Open a browser and search for the desired website. Open the desired page of the website. At the top of the page at the address bar, the URL of the page will be displayed. Copy it. Next, open a new browser window and paste the copied content, the same will be opened. The text copied is the URL of the required page.
If you are looking for the Uniform Resource Locator of an image of a webpage, then after opening the webpage, click on the image and copy the address. The address copied can be used as a Uniform Resource Locator to navigate to the page directly. This will not open the web page, but only the image will be loaded.
Q #2) What are public and private Uniform Resource Locators and their uses?
Answer: A Uniform Resource Locator can be set as Public or Private. Permission to Read and search content only is allowed if it is Public. If features like create, edit, update, delete and index permissions are required then it needs to be Private allowing Read-Write permission.
Q #3) What are URNs and do they ensure the availability of the said resource?
Answer: URNs are identifiers assigned to a resource within a defined namespace. The URN does not ensure the existence of the resource. The URN resource may lose its existence, but the URN assigned to it remains attached to it.
Q #4) What is the relationship between URI, URN, and URL?
Answer: URN, URL, and URI are all identifiers that help in locating a resource on the Internet. URN and URL are subsets of URI. URL gives the location or the address of the resource on the Internet, and the URN gives the name of the specific resource.
Q #5) What is the difference between hyperlinks and Uniform Resource locators?
Answer: Uniform Resource Locator gives the location or the address of the resource on the Internet. Uniform Resource Locator invariably loads the specified page or the object (image/file) gets loaded. A hyperlink is a “clickable” text within a page. On clicking it, the browser navigates to another page or another location on the page.
Q #6) What is the scheme in a Uniform Resource Locator?
Answer: The URL’s first component is the scheme or protocol. It is information to the browser as to which standard method for transferring data or exchanging data needs to be used to process the request. A few standard protocols are HTTPS, HTTP, FT, etc.
Q #7) What are the main components of a Uniform Resource Locator?
Answer: URL’s main components are
- Scheme or protocol
- Host name or domain name
- Port
- Path Name
- Query string
- Fragment
Q #8) What is the significance of a port in a Uniform Resource Locator?
Answer: In Uniform Resource Locator port is optional. The default port for HTTP protocol is 80 and for HTTPS is 443. A server can host multiple applications/services from different ports. So, for a request to reach the correct application in these cases, the port needs to be mentioned. If not mentioned, the request will land in the default port and the request will be processed and the result may not be correct.
Conclusion
Uniform Resource Locator and Uniform Resource Name are both types of Uniform Resource Identifier. While Uniform Resource Locator gives the location of the resource on the Internet and also the protocol or scheme i.e., the mechanism to reach the resource. The other components give the details of the host, the port, path where the resource is located.
The URN gives the name of the resource. URN is a unique number given to a resource in a specified namespace. The URN list is published and is a standard. ISBN number is an example of ‘name space’ declared in a URN where each book is identified by a unique number.
The role of the Uniform Resource Locator in our lives can be best summarized by the quote of Donald A Norman
“Our information lives will be better served when we are free to get to our information easily and quickly from where ever we are, with any device available”.