The wai-routes package

[Tags: library, mit]

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

[Skip to ReadMe]

Properties

Versions0.1, 0.2, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.4.0, 0.4.1, 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.6.2, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1
Change logNone available
Dependenciesbase (>=4.6.0.1 && <4.7), blaze-builder (>=0.3.3.2 && <0.4), bytestring (>=0.10.0.2 && <0.11), http-types (>=0.8.3 && <0.9), mtl (>=2.1.2 && <2.2), template-haskell (>=2.8.0.0 && <2.9), text (>=0.11.3.1 && <0.12), wai (>=2.0.0 && <2.1), yesod-routes (>=1.2.0.6 && <1.3) [details]
LicenseMIT
AuthorAnupam Jain
Maintainerajnsit@gmail.com
StabilityExperimental
CategoryNetwork
Home pagehttps://github.com/ajnsit/wai-routes
Source repositoryhead: git clone http://github.com/ajnsit/wai-routes
this: git clone http://github.com/ajnsit/wai-routes/tree/v0.4.1(tag v0.4.1)
UploadedFri Feb 28 11:52:50 UTC 2014 by AnupamJain
DistributionsLTSHaskell:0.7.3, NixOS:0.8.1, Stackage:0.8.1
Downloads2358 total (170 in last 30 days)
Votes
1 []
StatusDocs available [build log]
Successful builds reported [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for wai-routes-0.4.1

Wai Routes (wai-routes-0.4.1)

Build Status

This package provides typesafe URLs for Wai applications.

Features:

It depends on yesod-routes package for the TH functionality (but not the rest of yesod). The aim is to provide a similar level of typesafe URL functionality to Wai applications as is available to Yesod applications.

Example Usage

The following builds a simple JSON service (using Aeson for JSON conversion)

{-# 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 = ...
-- Delete Single User
postUserDeleteR :: Int -> Handler MyRoute
postUserDeleteR userid = ...

-- 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

Changelog