Package com.couchbase.client.java.http
Class CouchbaseHttpClient
java.lang.Object
com.couchbase.client.java.http.CouchbaseHttpClient
A specialized HTTP client for making requests to Couchbase Server.
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());
}
}
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondelete(HttpTarget target, HttpPath path) Issues a DELETE request with default options.delete(HttpTarget target, HttpPath path, HttpDeleteOptions options) Issues a DELETE request with the given options.get(HttpTarget target, HttpPath path) Issues a GET request with default options (no query parameters).get(HttpTarget target, HttpPath path, HttpGetOptions options) Issues a GET request with the given options.patch(HttpTarget target, HttpPath path) Issues a PATCH request with no body and default options.patch(HttpTarget target, HttpPath path, HttpPatchOptions options) Issues a PATCH request with the given options.post(HttpTarget target, HttpPath path) Issues a POST request with no body and default options.post(HttpTarget target, HttpPath path, HttpPostOptions options) Issues a POST request with the given options.put(HttpTarget target, HttpPath path) Issues a PUT request with no body and default options.put(HttpTarget target, HttpPath path, HttpPutOptions options) Issues a PUT request with the given options.
-
Constructor Details
-
CouchbaseHttpClient
-
-
Method Details
-
get
Issues a GET request with default options (no query parameters).To specify query parameters, use the overload that takes
HttpGetOptionsor include the query string in the path. -
get
Issues a GET request with the given options.Specify query parameters via the options:
httpClient.get(target, path, HttpGetOptions.httpGetOptions() .queryString(Map.of("foo", "bar"))); -
post
Issues a POST request with no body and default options.To specify a request body, use the overload that takes
HttpPostOptions. -
post
Issues a POST request with the given 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("{}"))); -
put
Issues a PUT request with no body and default options.To specify a request body, use the overload that takes
HttpPutOptions. -
put
Issues a PUT request with the given options.Specify a request body via the options:
// form data httpClient.put(target, path, HttpPutOptions.httpPutOptions() .body(HttpBody.form(Map.of("foo", "bar"))); // JSON document httpClient.put(target, path, HttpPutOptions.httpPutOptions() .body(HttpBody.json("{}"))); -
patch
Issues a PATCH request with no body and default options.To specify a request body, use the overload that takes
HttpPatchOptions. -
patch
Issues a PATCH request with the given options.Specify a request body via the options:
// form data httpClient.patch(target, path, HttpPatchOptions.httpPatchOptions() .body(HttpBody.form(Map.of("foo", "bar"))); // JSON document httpClient.patch(target, path, HttpPatchOptions.httpPatchOptions() .body(HttpBody.json("{}"))); -
delete
Issues a DELETE request with default options. -
delete
Issues a DELETE request with the given options.
-