RomanErnst/erl/1.0.0

NOTE: the latest version is 2.1.1

Erl

Library for parsing and constructing URLs

Types

type alias Url =
{ protocol : String
, host : String
, port_ : Maybe Int
, pathname : String
, query : Query
, hash : String
}

Record that holds url attributes

Parse

parse : String -> Result String Url

Parse an url into a Url record

Erl.parse "http://hello.com/users/1?k=1&q=2#a/b"


Ok
    { protocol = "http",
    , host = "hello.com",
    , port_ = Just 2000,
    , pathname = "/users/1",
    , query = [ ("k", "1"), ("q", "2") ]
    , hash = "a/b",
    }

Construct

new : Url

Generate an empty Url record

Erl.new
    == { protocol = ""
       , host = ""
       , port_ = Nothing
       , pathname = ""
       , query = []
       , hash = ""
       }

Serialize

toString : Url -> String

Generate a url string from an Url record

url = { protocol = "http",
      , host = "www.hello.com",
      , port_ = Just 2000,
      , pathname = "/users/1",
      , query = [ ("k", "1"), ("q", "2") ]
      , hash = "a/b",
      }


Erl.toString url == "http://www.hello.com:2000/users/1?k=1&q=2#a/b"
toAbsoluteString : Url -> String

Generate a url that starts at the path

url = { protocol = "http",
      , host = "www.hello.com",
      , port_ = Just 2000,
      , pathname = "/users/1",
      , query = [ ("k", "1"), ("q", "2") ]
      , hash = "a/b",
      }


Erl.toAbsoluteString url == "/users/1?k=1&q=2#a/b"