purescheme-wai-routing-core-0.1.1.0: Simple Routing functions for Wai Applications
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Routing.Purescheme.Core.Entity

Synopsis

Documentation

entity :: EntityResponse e -> e Source #

Entity Accessor

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