Skip to content
Switch branches/tags
Go to file

Latest commit

Co-authored-by: Esteban Laver <>
Co-authored-by: Rich Ellis <>

Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Cloudant Java Client

Build Status Maven Central Javadocs

This is the official Cloudant library for Java.

Installation and Usage


dependencies {
    compile group: 'com.cloudant', name: 'cloudant-client', version: '2.19.1'

Gradle with optional okhttp-urlconnection dependency:

dependencies {
    compile group: 'com.cloudant', name: 'cloudant-client', version: '2.19.1'
    compile group: 'com.squareup.okhttp3', name: 'okhttp-urlconnection', version: '3.12.12'



Maven with optional okhttp-urlconnection dependency:


Optional OkHttp dependency

HTTP requests to the database are made using Adding the optional dependency for the okhttp-urlconnection changes the HttpURLConnection from the default JVM implementation to the OkHttp implementation. Note that to use OkHttp requires a minimum of Java 1.7.

The main use case that is supported by this optional dependency is configuration of connection pools on a per CloudantClient basis (see the javadoc for ClientBuilder.maxConnections). If the OkHttp dependency is available at runtime it will be used automatically. Not using OkHttp will result in a smaller application size.

Note: The configuration options ClientBuilder.customSSLSocketFactory and ClientBuilder.disableSSLAuthentication are not usable with the combination of the optional OkHttp dependency and Java versions of 8u252 or newer.

Getting Started

This section contains a simple example of creating a com.cloudant.client.api.CloudantClient instance and interacting with Cloudant.

For further examples and more advanced use cases see the javadoc for the version you are using. The source code for the tests in this github project also contains many examples of API usage.

// Create a new CloudantClient instance for account endpoint
CloudantClient client = ClientBuilder.account("example")

// Note: for Cloudant Local or Apache CouchDB use:
// ClientBuilder.url(new URL("yourCloudantLocalAddress.example"))
//              .username("exampleUser")
//              .password("examplePassword")
//              .build();

// Note: there are some convenience methods for IBM Bluemix
// To use the URL and credentials provided in VCAP metadata:
// ClientBuilder.bluemix(String vcapMetadata)
//              .build();
// To use an IAM API key:
// ClientBuilder.url("")
//              .iamApiKey("exampleApiKey")
//              .build();

// Show the server version
System.out.println("Server Version: " + client.serverVersion());

// Get a List of all the databases this Cloudant account
List<String> databases = client.getAllDbs();
System.out.println("All my databases : ");
for ( String db : databases ) {

// Working with data

// Delete a database we created previously.

// Create a new database.

// Get a Database instance to interact with, but don't create it if it doesn't already exist
Database db = client.database("example_db", false);

// A Java type that can be serialized to JSON
public class ExampleDocument {
  private String _id = "example_id";
  private String _rev = null;
  private boolean isExample;

  public ExampleDocument(boolean isExample) {
    this.isExample = isExample;

  public String toString() {
    return "{ id: " + _id + ",\nrev: " + _rev + ",\nisExample: " + isExample + "\n}";

// Create an ExampleDocument and save it in the database ExampleDocument(true));
System.out.println("You have inserted the document");

// Get an ExampleDocument out of the database and deserialize the JSON into a Java type
ExampleDocument doc = db.find(ExampleDocument.class,"example_id");


Server version = 1.0.2
All my databases: example_db, stuff, scores
You have inserted the document.
{ id: example_id,
  rev: 1-6e4cb465d49c0368ac3946506d26335d,
  isExample: true

There is significantly more documentation, including additional code samples and explanations, in the javadoc. The first page you land on when following the javadoc link includes a table of contents with further links to help guide you to the documentation you need. To find the additional information be sure to scroll down past the auto-generated summary tables and do not overlook the package overviews.

Related documentation


For information about contributing, building, and running tests see the

Using in Other Projects

The preferred approach for using java-cloudant in other projects is to use the Gradle or Maven dependency as described above.

Migrating to cloudant-java-sdk library

We have a newly supported Cloudant Java SDK named cloudant-java-sdk. For advice on migrating from this module see


Copyright © 2014, 2016 IBM Corp. All rights reserved.

Licensed under the apache license, version 2.0 (the "license"); you may not use this file except in compliance with the license. you may obtain a copy of the license at

Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. See the license for the specific language governing permissions and limitations under the license.


Before opening a new issue please consider the following:

  • Only the latest release is supported. If at all possible please try to reproduce the issue using the latest version.
  • Please check the existing issues to see if the problem has already been reported. Note that the default search includes only open issues, but it may already have been closed.
  • Cloudant customers should contact Cloudant support for urgent issues.
  • When opening a new issue here in github please complete the template fully.

Caching, Encryption, and Compression

Caching data at the client, when it is appropriate for the application, can often improve performance considerably. In some cases, it may also be desirable to encrypt or compress data at the client. There is no built-in support for caching, encryption or compression at the client in java-cloudant. Other Java libraries that are not officially supported by Cloudant, but can provide these capabilities are: