Parse a URL Into Components Without a Library

Last updated: November 29, 2026

Quick Overview

Write a parser that splits an absolute URL like 'https://[email protected]:8443/search/pizza?q=nyc&z=12#top' into scheme, userinfo, host, port, path, query parameters and fragment, applying default ports and percent-decoding.

Google
Software Engineering Fundamentals
Frontend Engineer
Google
November 29, 2026
Frontend Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Write a parser that splits an absolute URL like 'https://[email protected]:8443/search/pizza?q=nyc&z=12#top' into scheme, userinfo, host, port, path, query parameters and fragment, applying default ports and percent-decoding.

Front end and Chrome teams at Google handle URLs constantly, from deep links in Maps to navigation in the browser. The screen checks careful string handling in the right order of delimiters, defaults, and awareness of encoding pitfalls.

What the Interviewer Expects
  • Split on delimiters in the correct order: fragment, query, then authority
  • Handle optional userinfo and port
  • Fill default ports for http and https
  • Percent-decode query keys and values and treat + as space
  • Support repeated query keys
Key Topics to Cover
URL parsing
string handling
percent-encoding
HTTP basics
web security
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How do you parse IPv6 hosts like [::1]:8080?
  • Why is parsing URLs with regexes a security risk?
  • How would you resolve a relative URL against a base?
  • What is IDN and punycode and where does it apply?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Input is an absolute URL with scheme://.
  • Output dict: scheme (lowercased), user, host (lowercased), port (int, default 80/443), path (default /), query (dict of lists), fragment....
High-Level Design

Order matters. The fragment is everything after the first #, and it can contain ?, so strip it first. Then split off the query at the first ?. What remains is scheme://authority/path. The auth...


Submit Your Answer
Markdown supported