Safe Haskell | None |
---|
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.
- accept :: MonadSnap m => MediaType -> m a -> m a
- accepts :: MonadSnap m => [(MediaType, m a)] -> m a
- data MediaType
- (//) :: ByteString -> ByteString -> MediaType
- (/:) :: MediaType -> (ByteString, ByteString) -> MediaType
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.