wai-middleware-verbs: Route Wai middlewares based on HTTP verbs

[ bsd3, library, web ] [ Propose Tags ] [ Report a vulnerability ]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.0.5, 0.1.0, 0.1.1, 0.2.0, 0.3.0, 0.3.1, 0.3.2, 0.3.2.1, 0.4.0, 0.4.0.1 (info)
Dependencies base (>=4.8 && <5), bytestring, exceptions, hashable, http-types, mmorph, monad-control, monad-control-aligned, monad-logger, mtl, resourcet, transformers, transformers-base, unordered-containers, wai (>=3.2.1), wai-transformers (>=0.1.0) [details]
License BSD-3-Clause
Copyright 2018 Athan Clark
Author Athan Clark
Maintainer athan.clark@localcooking.com
Category Web
Home page https://github.com/athanclark/wai-middleware-verbs#readme
Bug tracker https://github.com/athanclark/wai-middleware-verbs/issues
Source repo head: git clone https://github.com/athanclark/wai-middleware-verbs
Uploaded by athanclark at 2018-03-22T17:08:55Z
Distributions
Reverse Dependencies 1 direct, 2 indirect [details]
Downloads 7351 total (45 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-03-22 [all 1 reports]

Readme for wai-middleware-verbs-0.4.0.1

[back to package description]

wai-middleware-verbs

Route to different Wai middleware based on the incoming HTTP verb detected.

Usage

This library depends on the wai-transformers package - we expect middleware to already be lifted to MiddlewareT m.

As an example, here could be your application:

import Network.Wai.Trans
import Network.Wai.Middleware.Verbs


myMid1 :: MiddlewareT (ReaderT Env m)
myMid2 :: Middleware

uploadResponse :: ByteString -> MiddlewareT m
uploadResponse _ = liftMiddleware myMid2

verbRoutes :: VerbListenerT (MiddlewareT m) m ()
verbRoutes = do
  get myMid1
  post uploadResponse

Then, to use your newly assembled verb-router, turn the Verbs into a Middleware:

verbMid :: MiddlewareT (ReaderT Env m)
verbMid = verbsToMiddleware verbRoutes

From there, you can deconstruct your monolithic monad stack back down to IO, and plug-it-in to your existing middleware.