snap-accept-0.1.0: Accept header branching for the Snap web framework

Safe HaskellNone

Snap.Accept

Contents

Description

Provides a simple interface for routing based on the value of the Accept header in the client's request. The functions accept and accepts mirror Snap's standard method and methods functions.

The most convenient way of building MediaType values is to use the IsString instance with OverloadedStrings.

 accept "application/json" serveJson

Simple constructor operators are also supplied if you prefer.

Synopsis

Accept routing

accept :: MonadSnap m => MediaType -> m a -> m aSource

Runs a Snap monad only if the request's Accept header allows for the given media type. If accepted, the response's Content-Type header is automatically filled in.

accepts :: MonadSnap m => [(MediaType, m a)] -> m aSource

Runs a Snap monad only if the request's Accept header allows for one of the given media types. If accepted, the expected type is passed to the given function and the response's Content-Type header is automatically filled in.

MediaType

data MediaType

An HTTP media type, consisting of the type, subtype, and parameters.

(//) :: ByteString -> ByteString -> MediaType

Builds a MediaType without parameters. Can produce an error if either type is invalid.

(/:) :: MediaType -> (ByteString, ByteString) -> MediaType

Adds a parameter to a MediaType. Can produce an error if either string is invalid.