As we discussed in the previous lesson, when you navigate to
http://www.learnhowtoprogram.com/courses, your browser makes a request to a web server. One of the most important parts of that request is the address you're visiting. That address is called the URL, short for Uniform Resource Locator, or URI, short for Uniform Resource Identifier. (The difference is largely semantics.) In this lesson, we'll explore the URL in detail.
Some elements must be included in the URL for a request to be successful:
The scheme defines how the client locates or acts upon the requested resource. In our example, the client will make a request using the http:// scheme. Other schemes include
file. The scheme is always followed by a colon; for the
http scheme, a colon and two slashes (
The host provides the details of where the requested resource is located. The host in a URL is either the domain name for the IP address or the IP address itself. In our example, the host is
The path consists of one or more segments separated by slashes and provides the name for identifying the resource requested. In our example, the path indicates the resource:
Not all elements in a URL are required. Here are two that are optional.
There may be times where the URL contents must provide additional details for a resource to be identified.
For example, if we use the search functionality on Learn How to Program, the server will need to know the input that we enter in order to know what search results to return. When we enter "internet" as our search parameter and press "Search", the request is made to this URL:
After the path in the URL, we see a
? symbol which indicates the beginning of a query string. In our example, there are 3 key-value pairs that make up the parameters being sent in the request:
You'll see our search parameter is one of them with a key of
search and a value of
internet. Query parameters are separated by the
& symbol when there is more than one.
With this information, the server will use the value to query the database for only the lessons that have the term
internet in them.
Another optional URL element is called a fragment.
Here is an example:
Fragments begin with a
# symbol and contain information that's typically processed by the client, rather than the server. In this example, "validations" is the
id of a
div in the
HTML document that is returned. The HTML page is extremely long but by adding the fragment, the browser will position the display of the page precisely at that element when displayed.
Visit the link in the example. In the address bar, change
callbacks. Note how the page is repositioned to show the
callbacks section at the top of the browser. If you remove the fragment, the position returns to the default top of the document.
Uniform Resource Identifier (URI)/Uniform Resource Locator (URL): The web address which specifies the location of the requested web resources.
Scheme: The part of the URL that indicates the protocol to be used in communication (e.g.
Host: The part of the URL that contains the domain name.
Path: The part of the URL that contains the resource name.
Query string: An optional part of a URL that contains parameters for querying a database; begins with the
? symbol; often used in a search request.
Fragment: An optional part of a URL that contains details for where the browser should display the information (e.g. on a particular