post
suspend fun post(target: HttpTarget, path: String, common: CommonOptions = CommonOptions.Default, body: HttpBody? = null, headers: List<Header> = emptyList()): CouchbaseHttpResponse
Content copied to clipboard
Issues a POST
request to the target Couchbase service.
If the path has variable parts, consider using formatPath to build the path string.
Request content and type is defined by body. Specifying a body automatically sets the "Content-Type" header appropriately.
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
runBlocking {
val response = httpClient.post(
target = HttpTarget.manager(), // port 8091 (or equivalent)
path = "/some/arbitrary/path",
body = HttpBody.form(
"color" to "green",
"number" to 37,
"ingredients" to "sugar & spice" // values are automatically url-encoded
)
)
println(response)
}
//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.post(
target = HttpTarget.manager(), // port 8091 (or equivalent)
path = formatPath("/some/arbitrary/path"),
body = HttpBody.json("{\"foo\":\"bar\"}")
)
println(response)
}
//sampleEnd
}