Created
March 4, 2014 08:11
-
-
Save YoEight/9342231 to your computer and use it in GitHub Desktop.
Aeson parsing and Snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Traversable (for) | |
| import Data.Aeson (Value, json) | |
| import Data.AttoParsec (parseOnly) | |
| import Snap.Core | |
| getPostJsonParam :: MonadSnap m => ByteString -> m (Maybe Value) | |
| getPostJsonParam key = do | |
| bsOpt <- getPostParam key | |
| for bsOpt $ \bs -> | |
| case parseOnly json bs of | |
| Left e -> fail e -- Of course, use a better way to handle that kind of error | |
| Right v -> return v | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment