URLs and the hosts that they name, the same way on both platforms.
This covers percent-encoding and query strings, resolving a URL against the document that it's in (as a browser does it), and the scheme and the origin of a URL. It also checks whether a URL's host is on the public internet, e.g. before you fetch a URL that a stranger gave you.
The library parses URLs with whatwg-url, which implements the URL Standard, so it parses a host as a browser does, e.g. 0x7f.1 as 127.0.0.1.
URLs and the hosts that they name, the same way on both platforms. This covers percent-encoding and query strings, resolving a URL against the document that it's in (as a browser does it), and the scheme and the origin of a URL. It also checks whether a URL's host is on the public internet, e.g. before you fetch a URL that a stranger gave you. The library parses URLs with whatwg-url, which implements the URL Standard, so it parses a host as a browser does, e.g. 0x7f.1 as 127.0.0.1.
(absolute-url base url)The url made absolute against base, the URL of the document that
it's in, as a browser does it, or nil when either doesn't parse as a
URL.
A path, a path from the root, a query alone or a URL without a scheme resolves against the base. An absolute URL stays as it is.
A base with an opaque path, such as a mailto URL, takes only a fragment.
An empty url names the document itself. A path doesn't go above the
root, so ../x in a document at the root is /x.
The `url` made absolute against `base`, the URL of the document that it's in, as a browser does it, or nil when either doesn't parse as a URL. A path, a path from the root, a query alone or a URL without a scheme resolves against the base. An absolute URL stays as it is. A base with an opaque path, such as a mailto URL, takes only a fragment. An empty `url` names the document itself. A path doesn't go above the root, so ../x in a document at the root is /x.
(host url)The host of the http or https URL url, in lower case.
The host of the http or https URL `url`, in lower case.
(ip-address s)The bytes of the IP address in the text s, as numbers, or nil for
anything else, e.g. a name or a hash.
An IPv4 address has four, and an IPv6 address sixteen. The text of an IPv6 address can have the brackets that a URL puts around it.
The bytes of the IP address in the text `s`, as numbers, or nil for anything else, e.g. a name or a hash. An IPv4 address has four, and an IPv6 address sixteen. The text of an IPv6 address can have the brackets that a URL puts around it.
(legal-url url)The url as the URL Standard serializes it, which is what each
platform's client gets, so that it parses the host that public? checked.
On the JVM, it also percent-encodes as UTF-8 each character that
java.net.URI can't take, e.g. a bracket in the path or a percent sign
that starts no escape.
A URL that's already in this form comes back unchanged. A host with letters outside ASCII gets its IDNA ASCII form. Text that isn't a URL stays as it is, except for the encoding on the JVM.
The `url` as the URL Standard serializes it, which is what each platform's client gets, so that it parses the host that public? checked. On the JVM, it also percent-encodes as UTF-8 each character that java.net.URI can't take, e.g. a bracket in the path or a percent sign that starts no escape. A URL that's already in this form comes back unchanged. A host with letters outside ASCII gets its IDNA ASCII form. Text that isn't a URL stays as it is, except for the encoding on the JVM.
(origin url)The scheme, host and port of the http or https URL url as a vector,
as the URL Standard and browsers parse them, or nil for any other URL
and for a URL without a host.
The host is in lower case, and a name with letters outside ASCII is in its IDNA ASCII form. When the URL names no port, the port is the scheme's default.
The scheme, host and port of the http or https URL `url` as a vector, as the URL Standard and browsers parse them, or nil for any other URL and for a URL without a host. The host is in lower case, and a name with letters outside ASCII is in its IDNA ASCII form. When the URL names no port, the port is the scheme's default.
(parts s)The parts of the URL s as it's written, before a parser normalizes
them, or nil when s has no scheme.
The parts are a map of :scheme, :authority, :userinfo, :host, :port, :path, :query and :fragment, each nil when the URL has none. The scheme is in lower case and the rest is as written, e.g. a port of 443 for https or a .. segment in the path, percent-encoded or not. Use this to check a URL, not to send a request.
The parts of the URL `s` as it's written, before a parser normalizes them, or nil when `s` has no scheme. The parts are a map of :scheme, :authority, :userinfo, :host, :port, :path, :query and :fragment, each nil when the URL has none. The scheme is in lower case and the rest is as written, e.g. a port of 443 for https or a .. segment in the path, percent-encoded or not. Use this to check a URL, not to send a request.
(percent-decode s)The string s with its percent-encoding undone. A plus sign stays a
plus sign and a % that starts no escape stays as it is. Bytes that
aren't UTF-8 become U+FFFD rather than throwing.
The string `s` with its percent-encoding undone. A plus sign stays a plus sign and a % that starts no escape stays as it is. Bytes that aren't UTF-8 become U+FFFD rather than throwing.
(percent-encode s)The string s percent-encoded for a query string, the same way on both
platforms. Spaces become %20, not +. Letters, digits and the marks
-_.!~*'() stay as they are.
The string `s` percent-encoded for a query string, the same way on both platforms. Spaces become %20, not +. Letters, digits and the marks -_.!~*'() stay as they are.
(public-host? url)Whether the host of the http or https URL url is on the public
internet by its text alone, without looking up the name: a public
address, or a name that public-name? accepts.
A name can still resolve to an address on a local network, which public? checks on the JVM and in Node. So use this where you can't look up a name or it costs too much, e.g. to check many links at once.
Whether the host of the http or https URL `url` is on the public internet by its text alone, without looking up the name: a public address, or a name that public-name? accepts. A name can still resolve to an address on a local network, which public? checks on the JVM and in Node. So use this where you can't look up a name or it costs too much, e.g. to check many links at once.
(public-name? host)Whether the domain name host is a name of the public internet.
Such a name has a dot in it, not counting a dot at its end. It also doesn't stay on a local network, as localhost, .local, .internal and .home.arpa do. A host whose last part is a number isn't a name but an IPv4 address, as a browser parses it, e.g. 10.0.0.1 or 0x7f.0.0.1.
Whether the domain name `host` is a name of the public internet. Such a name has a dot in it, not counting a dot at its end. It also doesn't stay on a local network, as localhost, .local, .internal and .home.arpa do. A host whose last part is a number isn't a name but an IPv4 address, as a browser parses it, e.g. 10.0.0.1 or 0x7f.0.0.1.
(public? url)Whether the host of the http or https URL url is on the public
internet rather than on the app's own device or network.
On the JVM each address that the name resolves to has to be public, and a name that doesn't resolve isn't public. In ClojureScript the host has to pass public-host?. When send! calls this in Node, each address of the name has to be public too.
Whether the host of the http or https URL `url` is on the public internet rather than on the app's own device or network. On the JVM each address that the name resolves to has to be public, and a name that doesn't resolve isn't public. In ClojureScript the host has to pass public-host?. When send! calls this in Node, each address of the name has to be public too.
(query-pairs s)The parameters of the query string s, decoded, as pairs of a name and
a value in their order, repeats included. A plus sign is a space, as in
the body of a form. A name without = has a nil value.
Use this rather than query-params when you have to refuse a repeated parameter, as an OAuth server does by RFC 6749, section 3.1.
The parameters of the query string `s`, decoded, as pairs of a name and a value in their order, repeats included. A plus sign is a space, as in the body of a form. A name without = has a nil value. Use this rather than query-params when you have to refuse a repeated parameter, as an OAuth server does by RFC 6749, section 3.1.
(query-params s)The parameters of the query string s, decoded, by name. A plus sign
is a space, as in the body of a form. When a name repeats, its last
value counts.
The parameters of the query string `s`, decoded, by name. A plus sign is a space, as in the body of a form. When a name repeats, its last value counts.
(query-string params)The query string for params, with keys and values percent-encoded and
nil values left out. A true value becomes the bare flag that some APIs
take.
The query string for `params`, with keys and values percent-encoded and nil values left out. A true value becomes the bare flag that some APIs take.
(same-origin? a b)Whether the URLs a and b have the same scheme, host and port. False
when a URL has no host.
Whether the URLs `a` and `b` have the same scheme, host and port. False when a URL has no host.
(scheme s)The scheme of the URL s in lower case, or nil for a relative URL. It
parses the scheme as a browser does, ignoring the tabs and line breaks
in s and the spaces and control characters in front.
The scheme of the URL `s` in lower case, or nil for a relative URL. It parses the scheme as a browser does, ignoring the tabs and line breaks in `s` and the spaces and control characters in front.
(split-credentials url)The url without the user name and the password that it holds, and
those as credentials for authorization, as a pair. The credentials are
nil when the URL holds none.
A URL such as https://user:pass@host/feed.xml holds them. Use this when you store a URL, to keep the password apart from the address, since addresses end up in files, logs and messages.
The password is hidden with secret/hide, so it prints as #<secret>.
The `url` without the user name and the password that it holds, and those as credentials for authorization, as a pair. The credentials are nil when the URL holds none. A URL such as https://user:pass@host/feed.xml holds them. Use this when you store a URL, to keep the password apart from the address, since addresses end up in files, logs and messages. The password is hidden with secret/hide, so it prints as #<secret>.
(web-url? s)Whether s is an http or https URL with a host.
Whether `s` is an http or https URL with a host.
(with-query url params)The url with params added to its query, encoded as in a query
string. The parameters go after those that the URL has, and before its
fragment.
The `url` with `params` added to its query, encoded as in a query string. The parameters go after those that the URL has, and before its fragment.
(without-trailing-slashes url)The url without the slashes at its end, e.g. the root of an API that
paths are joined to, in time linear in its length.
The `url` without the slashes at its end, e.g. the root of an API that paths are joined to, in time linear in its length.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |