Uribe v0.3.0 Uribe
URI builder for Elixir.
Uribe always receives URI struct in the first argument and always returns URI struct instead of value
method
Link to this section Summary
Functions
Add query to URI
Remove the entire path, query and set path
Set fragment for URI
Set host for URI
Set path for URI
Set port for URI. Receives only integer
Remove param from URI query
Toggle http/https
scheme for URI. If current scheme is nil or another, set https
Get value of query param. Returns nil if not exists
Link to this section Functions
Link to this function
add_query(uri, query)
Add query to URI
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.add_query(%{"foo" => "bar"})
iex> uri.query
"foo=bar"
iex> uri = URI.parse("https://google.com") |> Uribe.add_query(%{"foo" => "bar"}) |> Uribe.add_query(%{"foo" => "baz"})
iex> uri.query
"foo=baz"
iex> uri = URI.parse("https://google.com?foo=bar") |> Uribe.add_query(%{"foo" => "baz", "bar" => "baz"})
iex> uri.query
"bar=baz&foo=baz"
Link to this function
cut(uri, path)
Remove the entire path, query and set path
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.cut("/foo/bar")
iex> uri.path
"/foo/bar"
iex> uri = URI.parse("https://google.com#qux") |> Uribe.cut("/foo/bar")
iex> URI.to_string(uri)
"https://google.com/foo/bar"
iex> uri = URI.parse("https://google.com/bar?baz=qux#quux") |> Uribe.cut("/foo")
iex> URI.to_string(uri)
"https://google.com/foo"
Link to this function
fragment(uri, fragment)
Set fragment for URI
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.fragment("foo")
iex> uri.fragment
"foo"
iex> uri = URI.parse("http://google.com") |> Uribe.fragment(nil)
iex> uri.fragment
nil
iex> uri = URI.parse("google.com") |> Uribe.fragment("")
iex> uri.fragment
""
Link to this function
host(uri, host)
Set host for URI
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.host("yandex.ru")
iex> uri.host
"yandex.ru"
iex> uri = URI.parse("http://google.com") |> Uribe.host("localhost")
iex> uri.host
"localhost"
iex> uri = URI.parse("google.com") |> Uribe.host("")
iex> uri.host
""
Link to this function
path(uri, path)
Set path for URI
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.path("/foo/bar")
iex> uri.path
"/foo/bar"
iex> uri = URI.parse("https://google.com/bar") |> Uribe.path("/foo")
iex> URI.to_string(uri)
"https://google.com/foo"
Link to this function
port(uri, port)
Set port for URI. Receives only integer
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.port(9292)
iex> uri.port
9292
Link to this function
remove(uri, param)
Remove param from URI query
Examples
iex> uri = URI.parse("https://google.com?foo=bar&baz=foo") |> Uribe.remove("foo")
iex> uri.query
"baz=foo"
iex> uri = URI.parse("https://google.com?foo=bar&baz=foo") |> Uribe.remove("baz")
iex> uri.query
"foo=bar"
iex> uri = URI.parse("https://google.com?foo=bar&baz=foo") |> Uribe.remove(["baz", "foo"])
iex> uri.query
""
Link to this function
toggle_scheme(uri)
Toggle http/https
scheme for URI. If current scheme is nil or another, set https
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.toggle_scheme
iex> uri.scheme
"http"
iex> uri = URI.parse("http://google.com") |> Uribe.toggle_scheme
iex> uri.scheme
"https"
iex> uri = URI.parse("google.com") |> Uribe.toggle_scheme
iex> uri.scheme
"https"
Link to this function
value(uri, param)
Get value of query param. Returns nil if not exists
Examples
iex> uri = URI.parse("https://google.com") |> Uribe.add_query(%{"foo" => "bar", "baz" => "qux"})
iex> Uribe.value(uri, "baz")
"qux"
iex> uri = URI.parse("https://google.com") |> Uribe.add_query(%{"foo" => "bar"})
iex> Uribe.value(uri, "baz")
nil
iex> URI.parse("https://google.com") |> Uribe.value("foo")
nil