snap-extras-0.12.3.0: A collection of useful helpers and utilities for Snap web applications.

Safe HaskellNone
LanguageHaskell2010

Snap.Extras.JSON

Contents

Synopsis

Parsing JSON from Request Body

getBoundedJSON Source #

Arguments

:: (MonadSnap m, FromJSON a) 
=> Int64

Maximum size in bytes

-> m (Either String a) 

Parse request body into JSON or return an error string.

getJSON :: (MonadSnap m, FromJSON a) => m (Either String a) Source #

Try to parse request body as JSON with a default max size of 50000.

reqBoundedJSON Source #

Arguments

:: (MonadSnap m, FromJSON a) 
=> Int64

Maximum size in bytes

-> m a 

Demand the presence of JSON in the body with a size up to N bytes. If parsing fails for any reson, request is terminated early and a server error is returned.

reqJSON :: (MonadSnap m, FromJSON b) => m b Source #

Demand the presence of JSON in the body assuming it is not larger than 50000 bytes.

getJSONField :: (MonadSnap m, FromJSON a) => ByteString -> m (Either String a) Source #

Get JSON data from the given Param field

reqJSONField :: (MonadSnap m, FromJSON a) => ByteString -> m a Source #

Force the JSON value from field. Similar to getJSONField

Sending JSON Data

writeJSON :: (MonadSnap m, ToJSON a) => a -> m () Source #

Set MIME to 'application/json' and write given object into Response body.