Elm route

Posted on February 21, 2016

Today marks the first release of elm-route, a type safe route parsing DSL built on top of elm-combine.

Its main additions to the world of type safe route parsing are:

You can see a working demo here (source). Note that direct linking to routes in the demo does not work due to a limitation of Gihub Pages.

elm-route-parser is another type safe route parsing library. In contrast to elm-route, its more rigid matchers make it possible to have cleaner route constructors (for example, HomeR instead of HomeR ()). It does not yet provide automatic reverse routing support.


Here’s a short taste of what the DSL looks like:

type Sitemap
  = HomeR ()
  | UsersR ()
  | UserR Int
  | UserPostR (Int, String)

homeR = HomeR := static ""
usersR = UsersR := static "users"
userR = UserR := "users" <//> int
userPostR = UserPostR := "users" <//> int </> string
sitemap = router [homeR, usersR, userR, userPostR]

match : String -> Maybe Sitemap
match = Route.match sitemap

route : Sitemap -> String
route r =
  case r of
    HomeR () -> reverse homeR []
    UsersR () -> reverse usersR []
    UserR id -> reverse userR [toString id]
    UserPostR (uid, pid) -> reverse userPostR [toString uid, pid]

For more check out the README and the examples folder.