Copyright | Copyright (c) 2015, Michael Alan Dorman |
---|---|
License | MIT |
Maintainer | mdorman@jaunder.io |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
These relatively simple combinators can do simple extractions of data from the data returned by Database.Couch.External routines, as well as checking certain information about the actual response values.
- standardParse :: FromJSON a => ResponseParser a
- type ResponseParser = ExceptT Error (Reader (ResponseHeaders, Status, Value))
- runParse :: ResponseParser a -> Either Error (ResponseHeaders, Status, Value) -> Either Error a
- responseStatus :: ResponseParser Status
- responseHeaders :: ResponseParser ResponseHeaders
- responseValue :: ResponseParser Value
- checkStatusCode :: ResponseParser ()
- maybeGetHeader :: HeaderName -> ResponseParser (Maybe ByteString)
- getHeader :: HeaderName -> ResponseParser ByteString
- getContentLength :: ResponseParser Integer
- getDocRev :: ResponseParser DocRev
- getKey :: Text -> ResponseParser Value
- toOutputType :: FromJSON a => Value -> ResponseParser a
Our primary interface
standardParse :: FromJSON a => ResponseParser a Source
Check the status code for a successful value and tries to decode to the user's desired type if so
Lower-level interfaces
type ResponseParser = ExceptT Error (Reader (ResponseHeaders, Status, Value)) Source
A type synonym for the Monad we're operating in
runParse :: ResponseParser a -> Either Error (ResponseHeaders, Status, Value) -> Either Error a Source
Run a given parser over an initial value
responseStatus :: ResponseParser Status Source
Extract the response status from the Monad
responseHeaders :: ResponseParser ResponseHeaders Source
Extract the response headers from the Monad
responseValue :: ResponseParser Value Source
Extract the response value from the Monad
checkStatusCode :: ResponseParser () Source
Check the status code for the response
maybeGetHeader :: HeaderName -> ResponseParser (Maybe ByteString) Source
Try to retrieve a header from the response
getHeader :: HeaderName -> ResponseParser ByteString Source
Retrieve a header from the response, or return an error if it's not present
getContentLength :: ResponseParser Integer Source
Decode the Content-Length header from the response, or return an error if it's not present
getDocRev :: ResponseParser DocRev Source
Get the document revision (ETag header), or return an error if it's not present
getKey :: Text -> ResponseParser Value Source
Get the value of a particular key from the response value, or return an error if it's not found
toOutputType :: FromJSON a => Value -> ResponseParser a Source
Decode the response value to a particular type, or return an error if it can't be decoded