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 Details

    • 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 - the core through which to send the request.
      method - the HttpMethod for the request.
      path - the full URL path for the request.
  • Method Details

    • 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 calling withHeader("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 calling withHeader("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 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.
      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 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.
      Parameters:
      jsonBody - the JSON body to use, as a JsonObject.
    • 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 via bodyRaw(String).
      Parameters:
      form - the Form builder object used to set form parameters.
    • method

      public com.couchbase.client.deps.io.netty.handler.codec.http.HttpMethod method()
      Returns:
      the HttpMethod used 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 RestApiRequest message sent through the ClusterFacade when executing this request.
    • execute

      public rx.Observable<RestApiResponse> execute()
      Executes the API request in an asynchronous fashion. The return type is an Observable that 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 Observable of the result of the API call, which is a RestApiResponse.