wai-middleware-content-type: Route to different middlewares based on the incoming Accept header.

[ bsd3, library, web ] [ Propose Tags ]

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


[Skip to Readme]
Versions 0.0.0, 0.0.1, 0.0.2, 0.0.3, 0.0.3.1, 0.0.3.2, 0.0.3.3, 0.0.4, 0.1.0, 0.1.0.1, 0.1.1, 0.1.1.1, 0.2.0, 0.2.1, 0.3.0, 0.4.0, 0.4.1, 0.5.0, 0.5.0.1, 0.5.1, 0.5.2, 0.6.0, 0.6.1, 0.6.1.1, 0.6.1.2 (info)
Dependencies aeson, base (>=4.8 && <5), blaze-builder, blaze-html, bytestring, clay, exceptions, extractable-singleton, hashable, http-media, http-types, lucid, mmorph, monad-control, monad-control-aligned, monad-logger, mtl, resourcet, shakespeare, text, transformers, transformers-base, unordered-containers, urlpath (>=9.0.0), wai (>=3.2), wai-logger, 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-content-type#readme
Bug tracker https://github.com/athanclark/wai-middleware-content-type/issues
Source repo head: git clone https://github.com/athanclark/wai-middleware-content-type
Uploaded by athanclark at Wed Apr 11 15:52:14 UTC 2018
Distributions NixOS:0.6.1.2
Downloads 4577 total (59 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-04-13 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for wai-middleware-content-type-0.6.1.2

[back to package description]

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 (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.