The wai-routes package
Provides easy to use typesafe URLs for Wai Applications.
Sample usage follows (See examples/Example.hs in the source bundle for the full code) -
{-# LANGUAGE OverloadedStrings, TypeFamilies #-}
import Network.Wai
import Network.Wai.Middleware.Routes
import Data.IORef
-- The Site Argument
data MyRoute = MyRoute (IORef DB)
-- Generate Routes
mkRoute MyRoute [parseRoutes|
/ UsersR GET
/user/#Int UserR:
/ UserRootR GET
/delete UserDeleteR POST
|]
-- Define Handlers
-- All Users Page
getUsersR :: Handler MyRoute
getUsersR (MyRoute dbref) request = ...
-- Single User Page
getUserRootR :: Int -> Handler MyRoute
getUserRootR userid (MyRoute dbref) request = ...
-- Delete Single User
postUserDeleteR :: Int -> Handler MyRoute
postUserDeleteR userid (MyRoute dbref) request = ...
-- Define Application using RouteM Monad
myApp = do
db <- liftIO $ newIORef mydb
route (MyRoute db)
setDefaultAction $ staticApp $ defaultFileServerSettings "static"
-- Run the application
main :: IO ()
main = toWaiApp myApp >>= run 8080
Properties
| Versions | 0.1, 0.2, 0.2.1, 0.2.2, 0.2.3, 0.2.4 |
|---|---|
| Dependencies | base (≥3 & <5), blaze-builder (≥0.2.1.4 & <0.4), http-types (≥0.7), mtl, path-pieces, template-haskell, text, wai (≥1.3), yesod-routes (1.1.*) |
| License | MIT |
| Author | Anupam Jain |
| Maintainer | ajnsit@gmail.com |
| Stability | Experimental |
| Category | Network |
| Home page | https://github.com/ajnsit/wai-routes |
| Source repository | git clone http://github.com/ajnsit/wai-routes |
| Upload date | Sun May 19 09:56:40 UTC 2013 |
| Uploaded by | AnupamJain |
| Built on | ghc-7.6 |
Modules
Downloads
- wai-routes-0.2.4.tar.gz (Cabal source package)
- package description (included in the package)