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

[ bsd3, library, web ] [ Propose Tags ]

Please see the README on Github at https://git.localcooking.com/tooling/wai-middleware-verbs#readme


[Skip to Readme]
Versions 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 Thu Mar 22 17:08:55 UTC 2018
Distributions NixOS:0.4.0.1, openSUSE:0.3.2.1
Downloads 2395 total (26 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-03-22 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


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.