@hackage wai-middleware-content-type0.7.0
Route to different middlewares based on the incoming Accept header.
Categories
License
BSD-3-Clause
Maintainer
athan.clark@gmail.com
Links
Versions
Installation
Dependencies (27)
- aeson
- base >=4.11 && <5
- blaze-builder
- blaze-html
- bytestring
- clay Show all…
Dependents (3)
@hackage/wai-middleware-verbs, @hackage/sparrow, @hackage/nested-routes
wai-middleware-content-type
Route middlewares based on the incoming Accept HTTP header,
and other hints like the file extension (foo.txt) of the route
requested.
Usage
This package provides many combinators for turning various data
types into the response you'd expect. For instance,
blaze-html gives
us strictly Html data, right? We can be sure to only respond
with Html-compatible requests with our toolset:
import Network.Wai.Middleware.ContentType
import Network.Wai.Trans
myMiddleware :: MiddlewareT (ReaderT Env m)
contentTypeRoutes :: Monad m =>
FileExtListenerT urlbase (Status -> ResponseHeaders -> Response) m ()
contentTypeRoutes = do
blaze myBlazeResponse
cassius myCassiusResponse
text myTextResponse
contentMiddleware :: Monad m => MiddlewareT m
contentMiddleware app req respond =
fileExtsToMiddleware $
mapResponse (\f -> f status200 []) contentTypeRoutes
This library was designed for use with nested-routes, but it's all good if you want to use it separately.