Module uri

This module implements URI parsing as specified by RFC 3986.

Types

Url = distinct string
  Source Edit
Uri = object
  scheme*, username*, password*: string
  hostname*, port*, path*, query*, anchor*: string
  opaque*: bool
  Source Edit

Procs

proc `$`(url: Url): string {.
deprecated, raises: [], tags: []
.}
Deprecated since 0.9.6: Use Uri instead.   Source Edit
proc `/`(a, b: Url): Url {.
deprecated, raises: [], tags: []
.}

Joins two URLs together, separating them with / if needed.

Deprecated since 0.9.6: Use Uri instead.

  Source Edit
proc add(url: var Url; a: Url) {.
deprecated, raises: [], tags: []
.}

Appends url to url.

Deprecated since 0.9.6: Use Uri instead.

  Source Edit
proc initUri(): Uri {.
raises: [], tags: []
.}
Initializes a URI.   Source Edit
proc parseUri(uri: string; result: var Uri) {.
raises: [ValueError], tags: []
.}
Parses a URI. The result variable will be cleared before.   Source Edit
proc parseUri(uri: string): Uri {.
raises: [ValueError], tags: []
.}
Parses a URI and returns it.   Source Edit
proc combine(base: Uri; reference: Uri): Uri {.
raises: [], tags: []
.}

Combines a base URI with a reference URI.

This uses the algorithm specified in section 5.2.2 of RFC 3986.

This means that the slashes inside the base URI's path as well as reference URI's path affect the resulting URI.

For building URIs you may wish to use `/` instead.

Examples:

let foo = combine(parseUri("http://example.com/foo/bar"), parseUri("/baz"))
assert foo.path == "/baz"

let bar = combine(parseUri("http://example.com/foo/bar"), parseUri("baz"))
assert bar.path == "/foo/baz"

let bar = combine(parseUri("http://example.com/foo/bar/"), parseUri("baz"))
assert bar.path == "/foo/bar/baz"
  Source Edit
proc combine(uris: varargs[Uri]): Uri {.
raises: [], tags: []
.}
Combines multiple URIs together.   Source Edit
proc `/`(x: Uri; path: string): Uri {.
raises: [], tags: []
.}

Concatenates the path specified to the specified URI's path.

Contrary to the combine procedure you do not have to worry about the slashes at the beginning and end of the path and URI's path respectively.

Examples:

let foo = parseUri("http://example.com/foo/bar") / "/baz"
assert foo.path == "/foo/bar/baz"

let bar = parseUri("http://example.com/foo/bar") / "baz"
assert bar.path == "/foo/bar/baz"

let bar = parseUri("http://example.com/foo/bar/") / "baz"
assert bar.path == "/foo/bar/baz"
  Source Edit
proc `$`(u: Uri): string {.
raises: [], tags: []
.}
Returns the string representation of the specified URI object.   Source Edit