new Connection(url, request)
Creates a Connection to a CouchDB Instance.
| Name | Type | Description |
|---|---|---|
url |
String |
The base URL to the CouchDB Instance |
request |
Object |
An object supporting the 'request' interface |
Members
-
passwdString
-
Ths password to use for connecting to the CouchDB host
-
req_defaultsObject
-
Default request configuration. We set the accept header and configure
request to encode/decode json for us. -
requestObject
-
An Object fulfilling the request API
- See:
-
urlString
-
The url to the CouchDB instance
-
useCookieboolean
-
Indicates whether to use Cookie authentication
-
userString
-
The username to use for connecting to the couchdb host
Methods
-
delete(path, parms){Promise}
-
Convenience method to send a DELETE request to a CouchDB host.
Name Type Description pathString the path to the desired object below the host-URL
parmsObject Object containing key/vale pairs of parametrers to
be appended to the URL. Must be JSON encodable.Returns:
Promiseobject. If the promise resolves aCouchResultis returned, if it rejects aCouchErroris
returned.
-
get(path, parms){Promise}
-
Convenience method to send a GET request to a CouchDB host.
Name Type Description pathString the path to the desired object below the host-URL
parmsObject Object containing key/vale pairs of parametrers to
be appended to the URL must be JSON encodableReturns:
Promiseobject. If the promise resolves aCouchResultis returned, if it rejects aCouchErroris
returned.
-
head(path, parms){Promise}
-
Convenience method to send a HEAD request to a CouchDB host.
Name Type Description pathString the path to the desired object below the host-URL
parmsObject Object containing key/vale pairs of parametrers to
be appended to the URL. Must be JSON encodable.Returns:
Promiseobject. If the promise resolves aCouchResultis returned, if it rejects aCouchErroris
returned.
-
http_request(method, path, opts){Promise}
-
The bare-metal HTTP request handling function returning a promise.
WARNING: it is recommended to use make_request as it can handle
automatic cookie-based login/relogin.Name Type Description methodString The HTTP verb to be used in the request
pathString The relative path for the request
optsObject An Object containing optional parameters for the request:
Name Type Description headersObject Object containing key/value pairs of custom
HTTP HeadersparmsObject Object containing key/value pairs of parameters to
be appended to the URL must be JSON encodablebodyObject Object or Array to be JSON encoded and put into
the request bodyReturns:
Promiseobject. If the promise resolves aCouchResultis returned, if it rejects aCouchErroris
returned.
-
login_and_retry(){Promise}
-
Do a cookie-based login to the CouchDB and then retry a given request.
Returns:
a promise that either resolves successful to the
result of the specified request or is rejected because
of the failed authentication.
-
make_request(method, path, opts){Promise}
-
The central workhorse for HTTP requests. Does automatic login and relogin
in casse 'useCookie' is set on the connection and credentials have been
supplied.Name Type Description methodString The HTTP verb to be used in the request
pathString The relative path for the request
optsObject An Object containing optional parameters for the request:
Name Type Description headersObject Object containing key/value pairs of custom
HTTP HeadersparmsObject Object containing key/value pairs of parameters to
be appended to the URL must be JSON encodablebodyObject Object or Array to be JSON encoded and put into
the request bodyReturns:
Promiseobject. If the promise resolves aCouchResultis returned, if it rejects aCouchErroris
returned.
-
openDB(dbname, options){Promise}
-
Convenience method to open a database on a CouchDB host.
Name Type Description dbnameString the name of the database to be opened on the
database host.optionsObject options for creating the database.
Name Type Description createbool indicates whether the database should
be created by the host if it is not yet
existing.Returns:
Promiseobject. If the promise resolves aDatabaseis returned. In case the database does not exist and
cannot be created either, aCouchErroris thrown.
-
post(path, body, parms){Promise}
-
Convenience method to send a POST request to a CouchDB host.
Name Type Description pathString the path to the desired object below the host-URL
bodyObject Object or Array to be JSON encoded and put into
the request bodyparmsObject Object containing key/vale pairs of parametrers to
be appended to the URL must be JSON encodableReturns:
Promiseobject. If the promise resolves aCouchResultis returned, if it rejects aCouchErroris
returned.
-
put(path, body, parms){Promise}
-
Convenience method to send a PUT request to a CouchDB host.
Name Type Description pathString the path to the desired object below the host-URL
bodyObject Object or Array to be JSON encoded and put into
the request bodyparmsObject Object containing key/vale pairs of parametrers to
be appended to the URL must be JSON encodableReturns:
Promiseobject. If the promise resolves aCouchResultis returned, if it rejects aCouchErroris
returned.