Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data EntityResponse e
- entity :: EntityResponse e -> e
- data NegotiatedResponse
- mapEntity :: (a -> b) -> EntityResponse a -> EntityResponse b
- withCustomNegotiation :: GenericApplication NegotiatedResponse -> GenericApplication Response
- withCustomNegotiation' :: [ByteString] -> GenericApplication NegotiatedResponse -> GenericApplication Response
- negotiated :: [(ByteString, a -> ByteString)] -> EntityResponse a -> NegotiatedResponse
- ok :: a -> EntityResponse a
- created :: a -> EntityResponse a
- notFound :: a -> EntityResponse a
- badRequest :: a -> EntityResponse a
- entityResponse :: Status -> ResponseHeaders -> a -> EntityResponse a
- requestEntity :: [(ByteString, ByteString -> Either String a)] -> (a -> GenericApplication b) -> GenericApplication b
Documentation
data EntityResponse e Source #
Instances
HasResponseHeaders (EntityResponse a) Source # | |
Defined in Network.Wai.Routing.Purescheme.Core.Entity mapResponseHeaders :: (ResponseHeaders -> ResponseHeaders) -> EntityResponse a -> EntityResponse a Source # |
entity :: EntityResponse e -> e Source #
Entity Accessor
data NegotiatedResponse Source #
Instances
HasResponseHeaders NegotiatedResponse Source # | |
mapEntity :: (a -> b) -> EntityResponse a -> EntityResponse b Source #
Maps a entity response
withCustomNegotiation :: GenericApplication NegotiatedResponse -> GenericApplication Response Source #
Converts an application of NegotiatedResponse to a normal WAI Application
This will reject the request with not acceptable (406) in case the content negotation fail
Note: This is going to do the content negotiation after the inner application has repond with
a NegotiatedResponse. That means, any IO is performed before the conetent negoatiation happen.
TODO: Find another way to do custom negotiation
Better to use @withCustomNegotiation'
withCustomNegotiation' :: [ByteString] -> GenericApplication NegotiatedResponse -> GenericApplication Response Source #
The same than @withCustomNegotiation
but checking the Accept header before doing any IO
negotiated :: [(ByteString, a -> ByteString)] -> EntityResponse a -> NegotiatedResponse Source #
Converts a entity response to a negotiated entity
ok :: a -> EntityResponse a Source #
Creates an entity response with status 200
created :: a -> EntityResponse a Source #
Creates a entity response with status 201
notFound :: a -> EntityResponse a Source #
Creates an entity response with status 404
badRequest :: a -> EntityResponse a Source #
Creates an entity response with status 400
entityResponse :: Status -> ResponseHeaders -> a -> EntityResponse a Source #
Creates a entity response with the provided status and response headers
requestEntity :: [(ByteString, ByteString -> Either String a)] -> (a -> GenericApplication b) -> GenericApplication b Source #
Reads the entity and pass it to provided function
The map provides the accepted media types with the functions that decodes it
As specified in https://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1 a missing content type header from the request is treated "application/octet-stream"
Note: This will read all the payload in memory and then decode it so it can blow up the memory. Better to have a guard on the size of the request