A URL stands for Uniform Resource Locator. In simple terms, a URL is like the street address of a resource on the internet. Just as a GPS needs a specific, unique address to find a location, your browser or API client needs a URL to find a specific file, data endpoint, or service hosted on a server.
A URL is essentially an address used by a web browser or application to locate a resource on the internet. While they can seem complex, they follow a predictable, structured format.
The general format is:
scheme://authority/path?query#fragment
The scheme or protocol defines the set of rules used to retrieve the resource. It specifies how the browser should communicate with the server.
http: (HyperText Transfer Protocol)https: (HyperText Transfer Protocol Secure - the standard for secure web traffic)The authority component is often prefixed with // and identifies the server hosting the resource. It is typically broken down into:
api.example.com or 192.0.2.1.80 for HTTP, 443 for HTTPS).
api.example.com:8080The path identifies the specific resource on the server. This often resembles the file structure of the server, but in modern web APIs, it often represents a hierarchy of resources.
https://api.example.com/users/123/orders, the path is /users/123/orders. The path starts after the host and port, and ends before the first ? or #.The query string is used to pass additional parameters or data to the server, often to filter, sort, or paginate the requested resource. It begins with a question mark (?) and consists of key-value pairs separated by ampersands (&).
.../products?category=electronics&sort=price, the query string is category=electronics&sort=price.
category, sortelectronics, priceThe fragment (or hash) component begins with a hash symbol (#) and is used to identify a specific section or portion of the resource. Critically, the fragment is usually processed by the browser and is NOT sent to the server in an HTTP request.
.../document.html#section-3, the fragment is section-3. This tells the browser to scroll to the element with the ID section-3 on the page.Let's look at a complete example:
https://dev.example.com:443/api/v1/users?active=true#profile-info
| Component | Value | Role | |
|---|---|---|---|
| Scheme | https |
Defines the secure communication protocol. | |
| Host | dev.example.com |
The server's domain name. | |
| Port | 443 |
The standard HTTPS port (often omitted). | |
| Path | /api/v1/users |
The resource being requested (a collection of users). | |
| Query | active=true |
A parameter to filter the results (only active users). | |
| Fragment | profile-info |
A section on the client-side, not sent to the server. |
<aside> ⌨️
Hands on: Break down this URL into its components:
https://deckofcards.com/api/deck/734iqo5k0u8b/draw/?count=1
</aside>
In JavaScript you can create a URL object from a string and then access its component parts as properties on this object. This works in browsers as well as in Node.js.
const myUrl = new URL('<http://example.com:8080/path?name=value#hash>');
console.log(myUrl.protocol); // Output: http:
console.log(myUrl.hostname); // Output: example.com
console.log(myUrl.port); // Output: 8080
console.log(myUrl.pathname); // Output: /path
console.log(myUrl.hash); // Output: #hash
console.log(myUrl.search); // Output: ?name=value

Found a mistake or have a suggestion? Let us know in the feedback form.