Copyright | Copyright (c) 2015, Michael Alan Dorman |
---|---|
License | MIT |
Maintainer | mdorman@jaunder.io |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module is about things that are at such a low level, they're not even necessarily really CouchDB-specific.
- rawJsonRequest :: MonadIO m => Manager -> Request -> m (Either Error (ResponseHeaders, Status, CookieJar, Value))
- structureRequest :: MonadIO m => RequestBuilder () -> ResponseParser a -> Context -> m (Result a)
- standardRequest :: (FromJSON a, MonadIO m) => RequestBuilder () -> Context -> m (Result a)
Documentation
:: MonadIO m | |
=> Manager | The Network.HTTP.Client.Manager to use for the request |
-> Request | The actual request itself |
-> m (Either Error (ResponseHeaders, Status, CookieJar, Value)) |
Make an HTTP request returning a JSON value
This is our lowest-level non-streaming routine. It only handles performing the request and parsing the result into a JSON value.
It presumes:
- we will be receiving a deserializable JSON value
- we do not need to stream out the result (though the input is parsed incrementally)
The results of parsing the stream will be handed to a routine that take the output and return the value the user ultimately desires. We use Data.Either to handle indicating failure and such.
Basing the rest of our library on a function where all dependencies are explicit should help make sure that other bits remain portable to, say, streaming interfaces.
:: MonadIO m | |
=> RequestBuilder () | The builder for the HTTP request |
-> ResponseParser a | A parser for the data type the requester seeks |
-> Context | A context for holding the HTTP manager and the cookie jar |
-> m (Result a) |
Higher-level wrapper around rawJsonRequest
Building on top of 'rawJsonRequest, this routine is designed to take a builder for the request and a parser for the result, and use them to request our transaction. This makes for a very declarative style when defining individual endpoints for CouchDB.
In order to support more sophisticated forms of authentication than
Basic
, we do have to examine the cookie jar returned from the
server, and perhaps tell the user that they should replace the cookie
jar in their context with it.
standardRequest :: (FromJSON a, MonadIO m) => RequestBuilder () -> Context -> m (Result a) Source
Make a HTTP request with standard CouchDB semantics
This builds on structureRequest
, with a standard parser for the
response.