Skip to content
bfad edited this page Dec 29, 2014 · 1 revision

Server API

Implemented in version 0.1.0

The CouchDB Server API can be found here: http://docs.couchdb.org/en/stable/api/server/index.html

The interface to the API is implemented by the couchDB_server type's member methods. These methods are named with a name that corresponds to the URL path. (For example, couchDB_server->allDBs corresponds to the "/_all_dbs" API.) For those URL paths with multiple HTTP methods, the following has been added to the base method name: "Create" for "POST" requests, "Update" for "PUT" requests, and "Delete" for "DELETE" requests. For example couchDB_server->sessionCreate corresponds to "POST"ing to the "/_session" path. Any parameters or data that can or must be passed as part of the request are taken as parameters to the member method. Examining the code should make it obvious how to call the member method to correctly generate the desired request.

Some examples of using this interface

    
    define db_main => couchDB_server("127.0.0.1", -noSSL, -username="admin", -password="12345")

    db_main->allDBs
    // => array(_replicator, _users)

    db_main->config('log', 'level')
    // => info

    db_main->configUpdate('log', 'level', 'debug')
    // => info 
    // (It returns the previous value... see below)

    db_main->config('log', 'level')
    // => info

Some requests that return JSON objects become objects of couchResponse_ types instead of maps. For example, the couchDB_server->session method returns a couchResponse_session object which has a member method couchResponse_session->userContext that returns a couchResponse_userContext object. That means I can get the username of the currently authenticated user by issuing the following request:

    
    db_main->session->userContext->name
    // => admin
Clone this wiki locally