Description
Declarative routing for WAI.
Description
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 $ ...
README.md
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.