@InterfaceAudience.Public @InterfaceStability.Experimental public class RestBuilder extends Object implements RestBuilderMarker
| Constructor and Description |
|---|
RestBuilder(AsyncRestBuilder asyncBuilder,
long defaultTimeout,
TimeUnit defaultTimeUnit) |
| Modifier and Type | Method and Description |
|---|---|
RestBuilder |
accept(String type)
Sets the "Accept" standard header's value.
|
RestApiRequest |
asRequest() |
String |
body() |
RestBuilder |
body(JsonValue jsonBody)
Sets the body for the request, assuming it is JSON.
|
RestBuilder |
body(String jsonBody)
Sets the body for the request, assuming it is JSON.
|
RestBuilder |
bodyForm(Form form)
Sets the body for the request to be an url-encoded form.
|
RestBuilder |
bodyRaw(String body)
Sets the body for the request without assuming a Content-Type or Accept header.
|
RestBuilder |
contentType(String type)
Sets the "Content-Type" standard header's value.
|
RestApiResponse |
execute()
Executes the API request in a synchronous fashion, using the default timeout.
|
RestApiResponse |
execute(long timeout,
TimeUnit timeUnit)
Executes the API request in a synchronous fashion, using the given timeout.
|
Map<String,Object> |
headers() |
com.couchbase.client.deps.io.netty.handler.codec.http.HttpMethod |
method() |
Map<String,String> |
params() |
String |
path() |
RestBuilder |
withHeader(String key,
Object value)
Adds an HTTP header to the request.
|
RestBuilder |
withParam(String key,
String value)
Adds an URL query parameter to the request.
|
public RestBuilder(AsyncRestBuilder asyncBuilder, long defaultTimeout, TimeUnit defaultTimeUnit)
asyncBuilder - defaultTimeout - defaultTimeUnit - public RestBuilder withParam(String key, String value)
key - the parameter key.value - the parameter value.public RestBuilder contentType(String type)
withHeader("Content-Type", type).type - the "Content-Type" to use.public RestBuilder withHeader(String key, Object value)
key - the header name (see HttpHeaders.Names for standard names).value - the header value (see HttpHeaders.Values for standard values).public RestBuilder body(String jsonBody)
"Content-Type" to "application/json"
and then setting the body via bodyRaw(String).
Note that you should avoid calling this for HTTP methods where it makes no sense
(eg. GET, DELETE), as it won't be ignored for these types of requests.jsonBody - the JSON body to use, as a String.public RestBuilder body(JsonValue jsonBody)
"Content-Type" to "application/json"
and then setting the body via bodyRaw(String).
Note that you should avoid calling this for HTTP methods where it makes no sense
(eg. GET, DELETE), as it won't be ignored for these types of requests.jsonBody - the JSON body to use, as a JsonObject.public RestBuilder bodyRaw(String body)
body - the raw body value to use, as a String.public RestBuilder accept(String type)
withHeader("Accept", type).type - the "Accept" type to use.public RestBuilder bodyForm(Form form)
"Content-Type" to "application/x-www-form-urlencoded"
and then setting the body via bodyRaw(String).form - the Form builder object used to set form parameters.public com.couchbase.client.deps.io.netty.handler.codec.http.HttpMethod method()
HttpMethod used for this request.public String path()
public Map<String,String> params()
public Map<String,Object> headers()
public String body()
public RestApiRequest asRequest()
RestApiRequest message sent through the ClusterFacade
when executing this request.public RestApiResponse execute(long timeout, TimeUnit timeUnit)
timeout - the custom timeout to use for the request.timeUnit - the TimeUnit for the timeout.RestApiResponse.RuntimeException - wrapping a TimeoutException in case the request took too long.public RestApiResponse execute()
view timeout.RestApiResponse.RuntimeException - wrapping a TimeoutException in case the request took too long.Copyright © 2015 Couchbase, Inc.