public class CouchbaseHttpClient extends Object
Get an instance by calling Cluster.httpClient()
.
Example usage:
public static String getAutoFailoverSettings(Cluster cluster) { HttpResponse response = cluster.httpClient().get( HttpTarget.manager(), HttpPath.of("/settings/autoFailover")); if (!response.success()) { throw new RuntimeException( "Failed to get auto-failover settings. HTTP status code " + response.statusCode() + "; " + response.contentAsString()); } return response.contentAsString(); } public static void disableAutoFailover(Cluster cluster) { HttpResponse response = cluster.httpClient().post( HttpTarget.manager(), HttpPath.of("/settings/autoFailover"), HttpPostOptions.httpPostOptions() .body(HttpBody.form(Map.of("enabled", "false")))); if (!response.success()) { throw new RuntimeException( "Failed to disable auto-failover. HTTP status code " + response.statusCode() + "; " + response.contentAsString()); } }
Constructor and Description |
---|
CouchbaseHttpClient(AsyncCouchbaseHttpClient async) |
Modifier and Type | Method and Description |
---|---|
HttpResponse |
delete(HttpTarget target,
HttpPath path)
Issues a DELETE request with default options.
|
HttpResponse |
delete(HttpTarget target,
HttpPath path,
HttpDeleteOptions options)
Issues a DELETE request with the given options.
|
HttpResponse |
get(HttpTarget target,
HttpPath path)
Issues a GET request with default options (no query parameters).
|
HttpResponse |
get(HttpTarget target,
HttpPath path,
HttpGetOptions options)
Issues a GET request with the given options.
|
HttpResponse |
post(HttpTarget target,
HttpPath path)
Issues a POST request with no body and default options.
|
HttpResponse |
post(HttpTarget target,
HttpPath path,
HttpPostOptions options)
Issues a POST request with the given options.
|
HttpResponse |
put(HttpTarget target,
HttpPath path)
Issues a PUT request with no body and default options.
|
HttpResponse |
put(HttpTarget target,
HttpPath path,
HttpPutOptions options)
Issues a PUT request with the given options.
|
@Stability.Internal public CouchbaseHttpClient(AsyncCouchbaseHttpClient async)
public HttpResponse get(HttpTarget target, HttpPath path)
To specify query parameters, use the overload that takes HttpGetOptions
or include the query string in the path.
public HttpResponse get(HttpTarget target, HttpPath path, HttpGetOptions options)
Specify query parameters via the options:
httpClient.get(target, path, HttpGetOptions.httpGetOptions() .queryString(Map.of("foo", "bar")));
public HttpResponse post(HttpTarget target, HttpPath path)
To specify a request body, use the overload that takes HttpPostOptions
.
public HttpResponse post(HttpTarget target, HttpPath path, HttpPostOptions options)
Specify a request body via the options:
// form data httpClient.post(target, path, HttpPostOptions.httpPostOptions() .body(HttpBody.form(Map.of("foo", "bar"))); // JSON document httpClient.post(target, path, HttpPostOptions.httpPostOptions() .body(HttpBody.json("{}")));
public HttpResponse put(HttpTarget target, HttpPath path)
To specify a request body, use the overload that takes HttpPutOptions
.
public HttpResponse put(HttpTarget target, HttpPath path, HttpPutOptions options)
Specify a request body via the options:
// form data httpClient.put(target, path, HttpPostOptions.httpPutOptions() .body(HttpBody.form(Map.of("foo", "bar"))); // JSON document httpClient.put(target, path, HttpPostOptions.httpPutOptions() .body(HttpBody.json("{}")));
public HttpResponse delete(HttpTarget target, HttpPath path)
public HttpResponse delete(HttpTarget target, HttpPath path, HttpDeleteOptions options)
Copyright © 2024 Couchbase, Inc.. All rights reserved.