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

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

Network.Wai.Middleware.ContentType

Contents

Description

Import this module to use all the application end-point combinators:


import Network.Wai.Middleware.ContentType
import qualified Data.Text as T
import qualified Lucid as L

myApp :: MonadIO m => MiddlewareT
myApp = fileExtsToMiddleware $ do
  text "Text!"
  json ("Json!" :: T.Text)
  lucid (L.toHtmlRaw ("Html!" :: T.Text))

If you would like to embed a MiddlewareT as a response to a particular supported file extension / content type, import Network.Wai.Middleware.ContentType.Middleware:

import Network.Wai.Middleware.ContentType
import Network.Wai.Middleware.ContentType.Middleware

myApp = fileExtsToMiddleware $
  middleware Css myMiddleware

Synopsis

Utilities

fileExtsToMiddleware :: MonadIO m => FileExtListenerT (MiddlewareT m) m () -> MiddlewareT m Source

Turn a map of content types to middlewares, into a middleware.

lookupResponse :: MonadIO m => Maybe AcceptHeader -> Maybe FileExt -> FileExtListenerT (MiddlewareT m) m () -> m (Maybe (MiddlewareT m)) Source

Given an HTTP Accept header and a content type to base lookups off of, and a map of responses, find a response.

possibleFileExts :: Maybe FileExt -> AcceptHeader -> [FileExt] Source

Takes a file extension and an Accept header, and returns the other file types handleable, in order of prescedence.

allFileExts :: [FileExt] Source

All file extensions, in the order of preference

Re-Exports