CouchbaseHttpClient

@Stability.Volatile
class CouchbaseHttpClient

Specialized HTTP client for the Couchbase Server REST API. Get an instance by calling Cluster.httpClient.

Instead of an explicit host and port, provide an HttpTarget identifying the service to invoke.

Samples

import com.couchbase.client.kotlin.Cluster
import com.couchbase.client.kotlin.manager.http.CouchbaseHttpClient
import com.couchbase.client.kotlin.manager.http.HttpBody
import com.couchbase.client.kotlin.manager.http.HttpTarget
import com.couchbase.client.kotlin.manager.http.NameValuePairs
import com.couchbase.client.kotlin.manager.http.formatPath
import kotlinx.coroutines.runBlocking
fun main() { 
   //sampleStart 
   // Using the Couchbase HTTP Client to interact with the
// Couchbase REST API.

// Assumes you have Couchbase running locally
// and the travel-sample bucket installed.

val cluster = Cluster.connect("127.0.0.1", "Administrator", "password")
val httpClient = cluster.httpClient()
val bucketName = "travel-sample"
try {
    runBlocking {
        // get bucket stats
        val response = httpClient.get(
            target = HttpTarget.manager(), // port 8091 (or equivalent)
            path = formatPath("/pools/default/buckets/{}/stats", bucketName)
        )

        with(response) {
            check(success) { "Request failed with status code $statusCode and content $contentAsString" }
            println(contentAsString)
        }
    }
} finally {
    runBlocking { cluster.disconnect() }
} 
   //sampleEnd
}

Functions

delete
Link copied to clipboard
suspend fun delete(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default): CouchbaseHttpResponse
get
Link copied to clipboard
suspend fun get(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, queryString: NameValuePairs? = null): CouchbaseHttpResponse
post
Link copied to clipboard
suspend fun post(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, body: HttpBody? = null): CouchbaseHttpResponse
put
Link copied to clipboard
suspend fun put(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, body: HttpBody? = null): CouchbaseHttpResponse