grafter.url

Utilities and protocols for building and handling URLs and URIs.

->GrafterURL

(->GrafterURL scheme host port path-segments query-params url-fragment)

Positional factory function for class grafter.url.GrafterURL.

->java-url

(->java-url url)

Convert a URI into a java.net.URL.

->url

(->url uri-str)

Parses a given string into a GrafterURL record. If the represented URI contains any reserved characters, they should be encoded correctly in the input string.

append-path-segments

(append-path-segments url & segments)

FIXME: write docs

append-query-params

(append-query-params u & kvs)

Appends multiple query parameters to the query string in the specified order. Expects query parameters to be in key-value vector pairs. See also append-query-params*

append-query-params*

(append-query-params* u & kvs)

Appends multiple query parameters to the query string in the specified order. Unlike append-query-params this variant does not require parameters to be specified as [key value] tuples.

bodge-java-uri-qparams

(bodge-java-uri-qparams uri qparams)

java.net.URI has several deep bugs with encoding URI parts. Its constructor partially encodes query parameters (incorrectly) which results in problems when accessing them again.

This function uses reflection to set the query params to your (encoded) string that bypass the erroneous encoding in URI’s constructor.

Yes, this is a nasty bodge that may potentially break on future java versions, but it’s the only way to get correct encoding behaviour.

For more details see this blog post:

https://blog.stackhunter.com/2014/03/31/encode-special-characters-java-net-uri/

canonicalise

(canonicalise url)

This function sorts a java.net.URI’s query parameters alphabetically by their key to canonicalise a URI suitable for an ID or key. It returns a java.net.URI.

IURIable

protocol

members

->java-uri

(->java-uri url)

Convert into a java.net.URI

IURL

protocol

A protocol for manipulating URL objects. Implementations of this protocol should also implement the protocols IURLable and IURIable

members

append-path-segments*

(append-path-segments* url segments)

Append new path segments to the URL path.

append-query-param

(append-query-param url key value)

Append the key and value to the query parameters

host

(host url)

Get the host domain of the URL.

path-segments

(path-segments url)

Get the path segments for the URL.

port

(port this)

Get the port of the URL.

query-params

(query-params url)

Return the query parameters for the URL as an ordered sequence of key/value tuples.

scheme

(scheme this)

Get the URL scheme.

set-host

(set-host url host)

Set the host domain of the URL.

set-path-segments*

(set-path-segments* url segments)

Set the path segments to those supplied.

set-port

(set-port this port)

Set the port of the URL.

set-query-params

(set-query-params url hash-map)

Adds the map of key value pairs to the query params. Sorts the keys first to help provide guarantee’s around URL equality.

set-scheme

(set-scheme url scheme)

Set the URL scheme e.g. http, https.

set-url-fragment

(set-url-fragment url fragment)

Set the URL #fragment

url-fragment

(url-fragment url)

Get the URL fragment from the URL.

map->GrafterURL

(map->GrafterURL m__8876__auto__)

Factory function for class grafter.url.GrafterURL, taking a map of keywords to field values.

parse-path

(parse-path path-str)

FIXME: write docs

query-params-map

(query-params-map url)

Returns a map of query parameters from a URL query string. If there are duplicate keys, the last occurrence of each duplicate parameter wins.

e.g. with the following query parameters ?foo=1&foo=2&bar=3 the map {“foo” 2 “bar” 3} is returned.

set-path-segments

(set-path-segments url & segments)

FIXME: write docs

ToGrafterURL

protocol

Convert any IURIable into a Grafter URL object.

members

->grafter-url

(->grafter-url uri-str)