wai-middleware-verbs-0.2.0: Route different middleware responses based on the incoming HTTP verb.

Copyright(c) Athan Clark, 2015
LicenseBSD-3
Maintainerathan.clark@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Middleware.Verbs

Contents

Description

This module provides everything you need to respond depending on an HTTP verbs. The Combinators section defines the get, post and other functions you would expect in a toolset like this. The VerbListenerT object is constructed from the combinators, and turning it directly into a WAI MiddlewareT is easy with verbsToMiddleware.

myApp :: MonadIO => MiddlewareT m
myApp = verbsToMiddleware $ do
  get myMiddleware1
  put uploader myMiddleware2
  post uploader myMiddleware3
  delete myMiddleware4
  where
    uploader :: MonadIO m => Request -> m ()
    uploader req = liftIO $ print =<< getStrictRequestBody req

Synopsis

Combinators

get :: Monad m => r -> VerbListenerT r m () Source

For simple GET responses

post :: Monad m => (Request -> m ()) -> r -> VerbListenerT r m () Source

For simple POST responses

put :: Monad m => (Request -> m ()) -> r -> VerbListenerT r m () Source

For simple PUT responses

delete :: Monad m => r -> VerbListenerT r m () Source

For simple DELETE responses

Types

type VerbMap m r = HashMap Verb (Request -> m (), r) Source

A map from an HTTP verb, to a result and uploading method.

type Verb = StdMethod Source

Monad Transformer

newtype VerbListenerT r m a Source

This is the monad for our DSL - where r is the result type. We leave this polymorphic for ActionT for nested-routes.

myListener :: MonadIO m => VerbListenerT (MiddlewareT m) m ()
myListener = do
  get myMiddleware1
  post uploader myMiddleware2
  where
    uploader :: MonadIO Request -> m ()
    uploader req =
      liftIO $ print =<< strictRequestBody req

Constructors

VerbListenerT 

Fields

runVerbListenerT :: StateT (VerbMap m r) m a
 

Instances

MonadReader r m => MonadReader r (VerbListenerT r m) Source 
MonadWriter w m => MonadWriter w (VerbListenerT r m) Source 
MonadBase b m => MonadBase b (VerbListenerT r m) Source 
MonadError e' m => MonadError e' (VerbListenerT r m) Source 
MonadTrans (VerbListenerT r) Source 
Monad m => Monad (VerbListenerT r m) Source 
Functor m => Functor (VerbListenerT r m) Source 
MonadFix m => MonadFix (VerbListenerT r m) Source 
Monad m => Applicative (VerbListenerT r m) Source 
MonadPlus m => Alternative (VerbListenerT r m) Source 
MonadPlus m => MonadPlus (VerbListenerT r m) Source 
MonadIO m => MonadIO (VerbListenerT r m) Source 
MonadCont m => MonadCont (VerbListenerT r m) Source 
MonadThrow m => MonadThrow (VerbListenerT r m) Source 
MonadMask m => MonadMask (VerbListenerT r m) Source 
MonadCatch m => MonadCatch (VerbListenerT r m) Source 
(MonadResource m, MonadBase IO m) => MonadResource (VerbListenerT r m) Source 
MonadLogger m => MonadLogger (VerbListenerT r m) Source 
Monad m => MonadState (VerbMap m r) (VerbListenerT r m) Source 

Utilities

lookupVerb :: Monad m => Request -> Verb -> VerbMap m r -> m (Maybe r) Source

Take the monadic partial result of lookupVerb, and actually h the upload.

getVerb :: Request -> Verb Source

Fetches the HTTP verb from the WAI Request - defaults to GET.

mapVerbs :: Monad m => (r -> s) -> VerbListenerT r m () -> VerbListenerT s m () Source