Examples¶
Worked examples — each page is one real problem, the awkward way to solve it without URLPattern, and the URLPattern-shaped replacement. Every snippet has been verified against the test suite.
Web routing¶
- Route a multi-tenant API by subdomain
- Add subdomain routing to aiohttp
- Add subdomain routing to FastAPI
- Validate inbound webhooks by URL shape
Security¶
AI / model serving¶
- Match the KServe
/v2/modelsinference path - Pick an LLM backend by model name
- Replace MCP resource URI templates
- Translate
google.api.httpto URLPattern
Text + data pipelines¶
- Classify GitHub URLs in markdown
- Extract YouTube video IDs from any URL form
- Match Slack callback IDs with structured data
Every example follows the same shape:
- The problem — what someone is actually trying to do, with a real public reference (issue link, blog post, framework doc).
- The awkward way — typical Python today:
urlparse+if host == …ladders, hand-rolled regex, or framework-specific config gymnastics. - With URLPattern — one declarative pattern, structured match result.
- What you get for free — which URLPattern feature carried the weight
(cross-component matching, optional segments, named groups with regex,
compare_component(), custom-scheme support, …).