URL

lib/URL.gob

URLs as RFC 3986 defines them, for any scheme: https://example.com/a?b, mailto:someone@example.com, urn:isbn:0451450523.

match URL.parse("https://example.com/search?q=turkey") {
    Right(u) -> print(URL.path(u))
    Left(e) -> print(e)
}

Two types. A URL is absolute: it has a scheme, so it names something on its own. A Reference may be relative, ../style.css or /orders/42 or ?page=2, and means something only against a base, which resolve supplies. Every URL is also a reference, through reference.

Strict. Every byte must be one RFC 3986 allows where it stands, and a % must start two hexadecimal digits. Spaces, controls, \, and bytes outside ASCII are refused rather than encoded or dropped, so the text a URL shows is exactly the text it was parsed from, apart from the scheme and host, which are case-insensitive and stored lowercase. Nothing else is normalized: dot segments stay as written until resolve, and percent-encoding is never added or removed.

Components are encoded. path, query and fragment are as they appear in the URL, %2F and all. segments decodes the path into its segments, where a%2Fb is one segment holding a slash, which no reading of the encoded path can tell apart from two.

type URL

An absolute URL: parts.scheme is always Some.

type Reference

A URL or a relative reference.

type Authority

The part after //: user@host:port.

type URLError = NotAbsolute | BadScheme | BadUserinfo | BadHost | BadPort | BadPath | BadQuery | BadFragment | UnsupportedScheme(String) | MissingHost | UserinfoNotAllowed

Why text is not a URL. Each names the component that was refused.

fun parse : fun(String) -> Either URLError URL

Returns the absolute URL text writes.

fun literal : fun(String) -> URL

Returns the URL text writes, and panics if it writes none: a URL written in the program's source that does not parse is a mistake in the program.

fun parseReference : fun(String) -> Either URLError Reference

Returns the URL or relative reference text writes.

fun referenceLiteral : fun(String) -> Reference

Returns the reference text writes, and panics if it writes none.

fun reference : fun(URL) -> Reference
fun scheme : fun(URL) -> String
fun authority : fun(URL) -> Option Authority
fun path : fun(URL) -> String
fun query : fun(URL) -> Option String
fun fragment : fun(URL) -> Option String
fun userinfo : fun(Authority) -> Option String
fun host : fun(Authority) -> String
fun port : fun(Authority) -> Option Int
fun segments : fun(URL) -> Option (Array String)

Returns the path's segments, decoded: /a%20b/c is ["a b", "c"]. The empty path has no segments, and / one empty segment. Returns None if a segment decodes to bytes that are not UTF-8.

fun decode : fun(String) -> Option String

Returns text with each %XX replaced by the byte it encodes, or None if the result is not UTF-8. text comes from a parsed URL, so every % starts two hexadecimal digits.

fun toString : fun(URL) -> String
fun resolve : fun(URL, Reference) -> URL

Returns the URL reference names when read against base, by the algorithm of RFC 3986 ยง5.2, dot segments removed.

instance Show URLError
instance Error URLError
instance Eq URL
instance Show URL
instance Eq Reference
instance Show Reference