Android - Put/get request

Hello,

I'm starting with Couchbase. I'm trying to make a put/get request from Android device to server with sync gateway.

I've tried like I make in CouchDB:

HttpClient httpClient = new DefaultHttpClient();
 
HttpPut put = new HttpPut("http://IP:4984/BUCKET");
 
put.setHeader("content-type", "application/json");
 
JSONObject oNode = new JSONObject();
oNode.put("field", "test");
StringEntity entity = new StringEntity(oNode.toString());
 
put.setEntity(entity);
 
HttpResponse resp = httpClient.execute(put);

But it doesn't work.
I've been looking for, but I'm not be able to find anything about how to do it. How can I do it?

Next, I'll test design documents with update functions, like CouchDB. Does it work in Couchbase server?

Thank you very much.

1 Answer

« Back to question.

Hello,

I am not sure to understand exactly what you are doing, but let me clarify some things.

1- If you are using Couchbase Lite (Couchbase on your mobile http://mobile.couchbase.com ) you have to use the local Android API and let the system synchronize with your Couchbase cluster using the Sync Gateway. You are not responsible of the "get/put" from the cluster this is done by the gateway

2- If you want to push date directly from your Android phone to the Couchbase cluster, (so you do not store any data on your mobile in Couchbase), you cannot use the gateway for that, it is not made for that. You have to create your own REST interface to get/put/delete data from your database.

Regards
Tug
@tgrall

Thank you very much indeed for your quick answer.

Yes, I am trying to push json data directly from a Android phone to the Couchbase cluster.

When I create a document through the REST API by the gateway:
 curl -X PUT -H 'Content-Type: application/json' http://IP:4984/sync_gateway/DOCUMENT_ID -d JSONDATA
the new document is created sucessfully, including the '_sync' data.

But I'm not able to push date in same way from phone. I've tried what I do in CouchDB, but it doesn´t work.

Finally, I found the problem.

My mistake was so simple like that in CouchDB you can push the data without the Document_Id, because it's automatically assigned. However, in Couchbase you must assign one.

Thank you very much, and sorry for the inconvenience.