The wai-routing package

[Tags: library, mpl]

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.

Example:

import Data.ByteString (ByteString)
import Data.Text (Text)
import Network.Wai
import Network.Wai.Predicate
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" (continue fetchUser) $
        capture "name"

    get "/user/find" (continue 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 -> Continue m -> m ResponseReceived
rmUser (name ::: foo) k = k $ ...

[Skip to ReadMe]

Properties

Versions0.1, 0.2, 0.3, 0.3.1, 0.4, 0.4.1, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.6, 0.7, 0.8, 0.9, 0.9.1, 0.10, 0.10.1, 0.10.2, 0.11, 0.11.1, 0.12, 0.12.1, 0.12.2, 0.12.3
Change logCHANGELOG.md
Dependenciesattoparsec (>=0.10 && <1.0), base (==4.*), bytestring (>=0.10 && <1.0), bytestring-conversion (>=0.2 && <1.0), case-insensitive (>=1.1 && <2.0), cookie (==0.4.*), http-types (>=0.8 && <1.0), transformers (>=0.3 && <0.5), wai (>=3.0 && <4.0), wai-predicates (==0.8.*), wai-route (==0.3.*) [details]
LicenseMPL-2.0
Copyright(C) 2014-2016 Toralf Wittner
AuthorToralf Wittner
MaintainerToralf Wittner <tw@dtex.org>
Stabilityexperimental
CategoryWeb
Home pagehttps://gitlab.com/twittner/wai-routing/
Bug trackerhttps://gitlab.com/twittner/wai-routing/issues
Source repositoryhead: git clone git@gitlab.com:twittner/wai-routing.git
UploadedSat Feb 13 21:21:03 UTC 2016 by ToralfWittner
DistributionsLTSHaskell:0.12.2, NixOS:0.12.2, Stackage:0.12.2
Downloads3192 total (77 in last 30 days)
Votes
0 []
StatusDocs pending
Build status unknown [no reports yet]

Modules

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for wai-routing-0.12.3

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.