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 path
String the path to the desired object below the host-URL
parms
Object Object containing key/vale pairs of parametrers to
be appended to the URL. Must be JSON encodable.Returns:
Promise
object. If the promise resolves aCouchResult
is returned, if it rejects aCouchError
is
returned.
-
get(path, parms){Promise}
-
Convenience method to send a GET request to a CouchDB host.
Name Type Description path
String the path to the desired object below the host-URL
parms
Object Object containing key/vale pairs of parametrers to
be appended to the URL must be JSON encodableReturns:
Promise
object. If the promise resolves aCouchResult
is returned, if it rejects aCouchError
is
returned.
-
head(path, parms){Promise}
-
Convenience method to send a HEAD request to a CouchDB host.
Name Type Description path
String the path to the desired object below the host-URL
parms
Object Object containing key/vale pairs of parametrers to
be appended to the URL. Must be JSON encodable.Returns:
Promise
object. If the promise resolves aCouchResult
is returned, if it rejects aCouchError
is
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 method
String The HTTP verb to be used in the request
path
String The relative path for the request
opts
Object An Object containing optional parameters for the request:
Name Type Description headers
Object Object containing key/value pairs of custom
HTTP Headersparms
Object Object containing key/value pairs of parameters to
be appended to the URL must be JSON encodablebody
Object Object or Array to be JSON encoded and put into
the request bodyReturns:
Promise
object. If the promise resolves aCouchResult
is returned, if it rejects aCouchError
is
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 method
String The HTTP verb to be used in the request
path
String The relative path for the request
opts
Object An Object containing optional parameters for the request:
Name Type Description headers
Object Object containing key/value pairs of custom
HTTP Headersparms
Object Object containing key/value pairs of parameters to
be appended to the URL must be JSON encodablebody
Object Object or Array to be JSON encoded and put into
the request bodyReturns:
Promise
object. If the promise resolves aCouchResult
is returned, if it rejects aCouchError
is
returned.
-
openDB(dbname, options){Promise}
-
Convenience method to open a database on a CouchDB host.
Name Type Description dbname
String the name of the database to be opened on the
database host.options
Object options for creating the database.
Name Type Description create
bool indicates whether the database should
be created by the host if it is not yet
existing.Returns:
Promise
object. If the promise resolves aDatabase
is returned. In case the database does not exist and
cannot be created either, aCouchError
is thrown.
-
post(path, body, parms){Promise}
-
Convenience method to send a POST request to a CouchDB host.
Name Type Description path
String the path to the desired object below the host-URL
body
Object Object or Array to be JSON encoded and put into
the request bodyparms
Object Object containing key/vale pairs of parametrers to
be appended to the URL must be JSON encodableReturns:
Promise
object. If the promise resolves aCouchResult
is returned, if it rejects aCouchError
is
returned.
-
put(path, body, parms){Promise}
-
Convenience method to send a PUT request to a CouchDB host.
Name Type Description path
String the path to the desired object below the host-URL
body
Object Object or Array to be JSON encoded and put into
the request bodyparms
Object Object containing key/vale pairs of parametrers to
be appended to the URL must be JSON encodableReturns:
Promise
object. If the promise resolves aCouchResult
is returned, if it rejects aCouchError
is
returned.