Class AsyncRestBuilder
- java.lang.Object
-
- com.couchbase.client.java.cluster.api.AsyncRestBuilder
-
- All Implemented Interfaces:
RestBuilderMarker
@Public @Experimental public class AsyncRestBuilder extends Object implements RestBuilderMarker
A builder class to incrementally construct REST API requests and execute them asynchronously- Since:
- 2.3.2
- Author:
- Simon Baslé
-
-
Constructor Summary
Constructors Constructor Description AsyncRestBuilder(String username, String password, ClusterFacade core, com.couchbase.client.deps.io.netty.handler.codec.http.HttpMethod method, String path)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncRestBuilderaccept(String type)Sets the "Accept" standard header's value.RestApiRequestasRequest()Stringbody()AsyncRestBuilderbody(JsonValue jsonBody)Sets the body for the request, assuming it is JSON.AsyncRestBuilderbody(String jsonBody)Sets the body for the request, assuming it is JSON.AsyncRestBuilderbodyForm(Form form)Sets the body for the request to be an url-encoded form.AsyncRestBuilderbodyRaw(String body)Sets the body for the request without assuming a Content-Type or Accept header.AsyncRestBuildercontentType(String type)Sets the "Content-Type" standard header's value.rx.Observable<RestApiResponse>execute()Executes the API request in an asynchronous fashion.Map<String,Object>headers()com.couchbase.client.deps.io.netty.handler.codec.http.HttpMethodmethod()Map<String,String>params()Stringpath()AsyncRestBuilderwithHeader(String key, Object value)Adds an HTTP header to the request.AsyncRestBuilderwithParam(String key, String value)Adds an URL query parameter to the request.
-
-
-
Constructor Detail
-
AsyncRestBuilder
public AsyncRestBuilder(String username, String password, ClusterFacade core, com.couchbase.client.deps.io.netty.handler.codec.http.HttpMethod method, String path)
- Parameters:
username- the username to authenticate the request with.password- the password to authenticate the request with.core- thecorethrough which to send the request.method- theHttpMethodfor the request.path- the full URL path for the request.
-
-
Method Detail
-
withParam
public AsyncRestBuilder withParam(String key, String value)
Adds an URL query parameter to the request. Using a key twice will result in the last call being taken into account.- Parameters:
key- the parameter key.value- the parameter value.
-
withHeader
public AsyncRestBuilder withHeader(String key, Object value)
Adds an HTTP header to the request. Using a key twice will result in the last value being used for a given header.- Parameters:
key- the header name (see "HttpHeaders.Names" for standard names).value- the header value (see "HttpHeaders.Values" for standard values).
-
bodyRaw
public AsyncRestBuilder bodyRaw(String body)
Sets the body for the request without assuming a Content-Type or Accept header. 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.- Parameters:
body- the raw body value to use, as a String.
-
contentType
public AsyncRestBuilder contentType(String type)
Sets the "Content-Type" standard header's value. This is a convenience method equivalent to callingwithHeader("Content-Type", type).- Parameters:
type- the "Content-Type" to use.
-
accept
public AsyncRestBuilder accept(String type)
Sets the "Accept" standard header's value. This is a convenience method equivalent to callingwithHeader("Accept", type).- Parameters:
type- the "Accept" type to use.
-
body
public AsyncRestBuilder body(String jsonBody)
Sets the body for the request, assuming it is JSON. This is equivalent to setting the"Content-Type"to"application/json"and then setting the body viabodyRaw(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.- Parameters:
jsonBody- the JSON body to use, as a String.
-
body
public AsyncRestBuilder body(JsonValue jsonBody)
Sets the body for the request, assuming it is JSON. This is equivalent to setting the"Content-Type"to"application/json"and then setting the body viabodyRaw(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.- Parameters:
jsonBody- the JSON body to use, as aJsonObject.
-
bodyForm
public AsyncRestBuilder bodyForm(Form form)
Sets the body for the request to be an url-encoded form. This is equivalent to setting the"Content-Type"to"application/x-www-form-urlencoded"and then setting the body viabodyRaw(String).- Parameters:
form- theFormbuilder object used to set form parameters.
-
method
public com.couchbase.client.deps.io.netty.handler.codec.http.HttpMethod method()
- Returns:
- the
HttpMethodused for this request.
-
path
public String path()
- Returns:
- the full HTTP path (minus query parameters) used for this request.
-
body
public String body()
- Returns:
- the body used for this request.
-
params
public Map<String,String> params()
- Returns:
- a copy of the query parameters used for this request.
-
headers
public Map<String,Object> headers()
- Returns:
- a copy of the HTTP headers used for this request.
-
asRequest
public RestApiRequest asRequest()
- Returns:
- the
RestApiRequestmessage sent through theClusterFacadewhen executing this request.
-
execute
public rx.Observable<RestApiResponse> execute()
Executes the API request in an asynchronous fashion. The return type is anObservablethat will only emit the result of executing the request. It is a cold Observable (and the request is only sent when it is subscribed to).- Returns:
- an
Observableof the result of the API call, which is aRestApiResponse.
-
-