get

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.

If the path has variable parts, consider using formatPath to build the path string.

Query parameters can be passed via queryString, and/or embedded in the path if you prefer.

There's usually no reason to set extra headers unless you're invoking an API that requires a special header.

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
}
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 
   runBlocking {
    val response = httpClient.get(
        target = HttpTarget.manager(), // port 8091 (or equivalent)
        path = formatPath("/some/arbitrary/path"),
        queryString = NameValuePairs.of(
            "color" to "green",
            "number" to 37,
            "ingredients" to "sugar & spice" // values are automatically url-encoded
        )
    )
    println(response)
} 
   //sampleEnd
}