CouchbaseHttpClient

@Stability.Volatile
class CouchbaseHttpClient

Specialized HTTP client for the Couchbase Server REST API. An instance is available as 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.http.CouchbaseHttpClient
import com.couchbase.client.kotlin.http.HttpBody
import com.couchbase.client.kotlin.http.HttpTarget
import com.couchbase.client.kotlin.http.NameValuePairs
import com.couchbase.client.kotlin.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

Link copied to clipboard
suspend fun delete(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, headers: List<Header> = emptyList()): CouchbaseHttpResponse

Issues a DELETE request to the target Couchbase service.

Link copied to clipboard
suspend fun get(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, queryString: NameValuePairs? = null, headers: List<Header> = emptyList()): CouchbaseHttpResponse

Issues a GET request to the target Couchbase service.

Link copied to clipboard
suspend fun post(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, body: HttpBody? = null, headers: List<Header> = emptyList()): CouchbaseHttpResponse

Issues a POST request to the target Couchbase service.

Link copied to clipboard
suspend fun put(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, body: HttpBody? = null, headers: List<Header> = emptyList()): CouchbaseHttpResponse

Issues a PUT request to the target Couchbase service.