Readme for wai-routing-0.3.1

wai-routing enables the declaration of "routes" which handle requests to a specific URL.

The set of possible handlers can be restricted by "predicates", which operate on WAI requests and have to be true or else the handler will not be called.

For details have a look at the haddock documentation of Network.Wai.Routing.Tutorial or the examples folder in the source distribution.

This library is a port of snap-predicates which provides similar functionality for the snap framework.

The routing tree construction is implemented using wai-route.

Here is a simple usage example.

import Data.ByteString (ByteString)
import Data.Text (Text)
import Network.Wai
import Network.Wai.Routing
import Network.Wai.Handler.Warp

main :: IO ()
main = run 8080 (route (prepare start))

start :: Monad m => Routes a m ()
start = do
    get "/user/:name" fetchUser $
        capture "name"

    get "/user/find" findUser $
        query "byName" :||: query "byId"

    delete "/user/:name" rmUser $
        capture "name" :&: opt (cookie "foo")

fetchUser :: Monad m => Text -> m Response
fetchUser name = ...

findUser :: Monad m => Either ByteString Word64 -> m Response
findUser (Left  name)  = ...
findUser (Right ident) = ...

rmUser :: Monad m => Text ::: Maybe Int -> m Response
rmUser (name ::: foo)  = ...