couch-simple-0.0.1.0: A modern, lightweight, complete client for CouchDB

CopyrightCopyright (c) 2015, Michael Alan Dorman
LicenseMIT
Maintainermdorman@jaunder.io
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Database.Couch.Internal

Description

This module is about things that are at such a low level, they're not even necessarily really CouchDB-specific.

Synopsis

Documentation

rawJsonRequest Source

Arguments

:: 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.

structureRequest Source

Arguments

:: 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.