🌐 Web Development

URL

Uniform Resource Locator

A web resource address. Composed of protocol, domain, and path.

📖 Detailed Explanation

URL (Uniform Resource Locator) is a standard addressing scheme that specifies the location of a resource on the internet. It consists of a protocol (https://), a host (www.example.com), a port (:443), a path (/path), a query string (?key=value), and a fragment (#section).

The URL was proposed by Tim Berners-Lee in 1994 as a core technology of the web. It is a subconcept of the URI (Uniform Resource Identifier): if a URI is an identifier of a resource, a URL indicates the location of a resource (including how to access it). In practice, URL and URI are used with almost the same meaning.

Each part of a URL has a clear role. The scheme specifies how to access the resource (http, https, ftp, etc.), the host is the server address, the path is the location of the resource within the server, the query string is for additional parameters, and the fragment specifies a particular location within the page.

In front-end development, URLs are directly tied to routing, SEO, and state management. In an SPA, the URL is manipulated with the History API, and frameworks like Next.js automatically generate the URL structure through file-based routing. URL encoding, decoding, and parsing are everyday tasks.

💻 Code Example

// JavaScript URL 다루기

// URL 파싱 (URL API 사용)
const url = new URL('https://example.com:8080/path/page?name=김철수&page=1#section');

console.log(url.protocol);  // "https:"
console.log(url.hostname);  // "example.com"
console.log(url.port);      // "8080"
console.log(url.pathname);  // "/path/page"
console.log(url.search);    // "?name=김철수&page=1"
console.log(url.hash);      // "#section"

// 쿼리 파라미터 다루기 (URLSearchParams)
const params = new URLSearchParams(url.search);
console.log(params.get('name'));  // "김철수"
console.log(params.get('page'));  // "1"

// 파라미터 추가/수정
params.set('sort', 'date');
params.append('tag', 'javascript');
console.log(params.toString());  // "name=김철수&page=1&sort=date&tag=javascript"

// URL 인코딩/디코딩
const korean = '한글 테스트';
const encoded = encodeURIComponent(korean);
console.log(encoded);  // "%ED%95%9C%EA%B8%80%20%ED%85%8C%EC%8A%A4%ED%8A%B8"
console.log(decodeURIComponent(encoded));  // "한글 테스트"

// React Router에서 URL 파라미터
// /users/:id 라우트에서
import { useParams, useSearchParams } from 'react-router-dom';

function UserPage() {
  const { id } = useParams();  // URL 경로 파라미터
  const [searchParams] = useSearchParams();  // 쿼리 파라미터
  const tab = searchParams.get('tab') || 'profile';
  // ...
}

🗣️ Say It Like This in Practice

💬 In an API design meeting
"To design it RESTfully, it's better to use nouns instead of verbs in the URL. Use GET /users instead of /getUsers, and access a specific user with /users/{id}, which is the standard. Query strings are used for filtering or pagination."
💬 In an Interview
"A URL consists of a protocol, host, port, path, query, and fragment. You parse it with the browser's URL API and manipulate query parameters with URLSearchParams. In an SPA, you change the URL without a page refresh using the History API's pushState."
💬 In a code review
"When you include user input in a URL, you must encode it with encodeURIComponent. Otherwise, special characters (&, =, ?) can break the URL structure or create security vulnerabilities."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Missing URL encoding

If you put Korean text or special characters directly into a URL, it breaks or malfunctions. Use encodeURIComponent(). However, for a full URL, use encodeURI().

❌
Exposing sensitive information in the URL

If you put passwords, tokens, etc. in the query string, they are exposed in the browser history, server logs, and the Referer header. Send sensitive information in the request body or headers.

✅
Proper URL design

Reflect the resource hierarchy in the URL, use lowercase letters and hyphens (-), and use meaningful path names. This helps both SEO and user experience.

🔗 Related Terms

📚 Learn More