---
source: https://iinventedlight.com/library/notes/go-net-url.md
title: "net/url: parse URLs and escape paths"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, net/url package reference; Go, net/url/url.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-net-url"
tags: [go, net, url, parse, query]
client: Librarian
sources:
  - id: S1
    title: "net/url package reference"
    publisher: Go
    url: https://pkg.go.dev/net/url
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "net/url/url.go source"
    publisher: Go
    url: https://go.dev/src/net/url/url.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
---
# net/url: parse URLs and escape paths
**Answer:** Package net/url represents a URL with scheme, host, path, query, and fragment fields. ParseRequestURI parses a raw url into a URL structure. Prefer EscapedPath over reading RawPath directly.

## The URL form

The general form is [scheme:][//[userinfo@]host][/]path[?query][#fragment].

ParseRequestURI parses a raw url into a URL structure.

The Host field contains the host and port subcomponents of the URL.

If a slash does not follow the scheme, the URL is read as scheme:opaque[?query][#fragment].

A hostname and path with no scheme is invalid to parse, though ambiguities mean an error is not guaranteed.

## EscapedPath, String, and Values

RawPath is optional and stores an encoded path hint.

EscapedPath returns RawPath when it is a valid escaping of Path. Otherwise it ignores RawPath and computes an escaped form on its own.

The String and RequestURI methods use EscapedPath to construct their results.

In general, call EscapedPath instead of reading u.RawPath directly.

If u.Opaque is non-empty, String uses the opaque form; otherwise it uses the host and path form.

Query parameters and form values typically go in a Values map. Those keys are case-sensitive, unlike keys in http.Header.

## See also

- [go-net-http-client](https://iinventedlight.com/library/notes/go-net-http-client/)
- [go-net-dial-listen](https://iinventedlight.com/library/notes/go-net-dial-listen/)
- [go-path-filepath](https://iinventedlight.com/library/notes/go-path-filepath/)

## Claims

- id: C1
  claim: The Host field contains the host and port subcomponents of the URL.
  source: S1
  evidence: "The Host field contains the host and port subcomponents of the URL"

- id: C2
  claim: ParseRequestURI parses a raw url into a URL structure.
  source: S1
  evidence: "ParseRequestURI parses a raw url into a URL structure"

- id: C3
  claim: Code should call EscapedPath instead of reading RawPath directly.
  source: S1
  evidence: "call EscapedPath instead of reading u.RawPath directly"

- id: C4
  claim: Keys in a Values map are case-sensitive.
  source: S1
  evidence: "the keys in a Values map are case-sensitive"

- id: C5
  claim: If Opaque is non-empty, String uses the opaque form.
  source: S1
  evidence: "If u.Opaque is non-empty, String uses the first form"

- id: C6
  claim: EscapedPath preserves the original encoding of Path.
  source: S2
  evidence: "the original encoding of Path"

## Sources

- [S1] net/url package reference. Go. https://pkg.go.dev/net/url . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] net/url/url.go source. Go. https://go.dev/src/net/url/url.go . License: BSD-3-Clause. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, net/url package reference; Go, net/url/url.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
