snap-web-routes

Type safe URLs for Snap

https://github.com/lukerandall/snap-web-routes

Latest on Hackage:0.5.1.0

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD-3-Clause licensed by Luke Randall
Maintained by [email protected]

Type safe URL generation and routing for Snap using web-routes, and builds on work done by Jeremy Shaw.

Get started with the comprehensive tutorial.

Brief overview

It allows you to define a data type that represents the routes in your application:

data AppUrl
    = Login                   -- routes to /login
    | Logout                  -- routes to /logout
    | User (Resource UserId)  -- provides RESTful routes at /user

Resource is documented in Snap.Snaplet.Router.REST, and makes defining RESTful routes easier. Also provided are functions to use the URL data type in your app:

someHandler :: Handler App App ()
someHandler :: doSomething >> redirectURL $ User Index

and to generate URLs in views:

linksHandler :: Handler App App ()
linksHandler = heistLocal (I.bindSplices linksSplices) $ render "links"
  where
    linksSplices = do
        "loginUrl" ## urlSplice Login