Library for parsing and constructing URLs
List of tuples that holds the keys and values in the query string
Parse a url string, returns an Erl.Url record
Erl.parse "http://api.example.com/users/1#x/1?a=1" == Erl.Url{...}Extract the hash (hash) from the url
Extract the host from the url
Extract the path from the url
Extract the protocol from the url
Extract the port from the url
If no port is included in the url then Erl will attempt to add a default port:
Http -> 80 Https -> 443 FTP -> 21 SFTP -> 22
Extract the query string from the url
Generate an empty Erl.Url record
Erl.new ==
{ protocol = ""
, username = ""
, password = ""
, host = []
, path = []
, hasLeadingSlash = False
, hasTrailingSlash = False
, port_ = 0
, hash = ""
, query = Dict.empty
}Adds key/value in query string
Erl.addQuery key value urlThis doesn't replace existing keys, so if this is a duplicated this key is just added.
Set key/value in query string, removes any existing one if necessary.
Erl.setQuery key value urlRemoves key from query string
Erl.removeQuery key urlClears the current query string
Erl.clearQuery urlAppend some path segments to a url
Erl.appendPathSegments ["hello", "world"] urlGenerate url string from an Erl.Url record
url = { protocol = "http",
, username = "",
, password = "",
, host = ["www", "foo", "com"],
, path = ["users", "1"],
, hasLeadingSlash = False
, hasTrailingSlash = False
, port_ = 2000,
, hash = "a/b",
, query = Dict.empty |> Dict.insert "q" "1" |> Dict.insert "k" "2"
}
Erl.toString url == "http://www.foo.com:2000/users/1?k=2&q=1#a/b"Convert to a string only the query component of an url, this includes '?'
Erl.queryToString url.query == "?a=1&b=2"Gets values for a key in the query
url = Erl.parse "?a=1&b=2&a=3"
Erl.getQueryValuesForKey "a" url
== ["1", "3"]
Record that holds url attributes