How to connect Clusterpoint database in android using REST api?

129 Views Asked by At

I am building an android app with Java. How do I connect to Clusterpoint by using REST? I need some example.

1

There are 1 best solutions below

0
On BEST ANSWER

You should set basic authorization. Here is an example:

URL url = new URL("https://api-eu.clusterpoint.com/ACCOUNT_ID/DATABASE/_ID");

HttpURLConnection uc = (HttpURLConnection) url.openConnection();
String userpass = "USERNAME" + ":" + "PASSWORD";
String basicAuth = "Basic "
            + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass
            .getBytes());

uc.setRequestProperty("Authorization", basicAuth);

// Receive response
InputStream in = uc.getInputStream();
InputStreamReader isr = new InputStreamReader(in);

int numCharsRead;
char[] charArray = new char[1024];
StringBuffer sb = new StringBuffer();
while ((numCharsRead = isr.read(charArray)) > 0) {
        sb.append(charArray, 0, numCharsRead);
}
String result = sb.toString();
System.out.println(result);

You can also find here more code examples: http://docs.clusterpoint.com/examples/