Class HttpClient

java.lang.Object
com.symphony.bdk.http.api.HttpClient

public class HttpClient extends Object
Generic Restful Client built on top of the ApiClient.

Usage example:


   final HttpClient httpClient = HttpClient.builder(() -> new ApiClientBuilder())
       .basePath("https://localhost:8080")
       .header("Connection", "Keep-Alive")
       .header("Keep-Alive", "timeout=5, max=1000")
       .cookie("foo", "bar")
       .build();

   final String response = httpClient.path("/api/v1/users")
       .header("Authorization", "Bearer AbCdEf123456")
       .get(new TypeReference<String>() {});
 
  • Method Details

    • method

      public <T> T method(String method, TypeReference<T> type) throws ApiException
      Build a request and execute it using an arbitrary request method name.
      Type Parameters:
      T - generic response type.
      Parameters:
      method - request method name.
      type - the TypeReference object representing a generic Java type the response should convert to.
      Returns:
      Response entity
      Throws:
      ApiException - if there are problems with the Api client request.
    • get

      public <T> T get(TypeReference<T> type) throws ApiException
      Build a get request and execute it.
      Type Parameters:
      T - generic response type.
      Parameters:
      type - the TypeReference object representing a generic Java type the response should convert to.
      Returns:
      Response entity.
      Throws:
      ApiException - if there are problems with the Api client request.
    • post

      public <T> T post(TypeReference<T> type) throws ApiException
      Build a post request and execute it.
      Type Parameters:
      T - generic response type.
      Parameters:
      type - the TypeReference object representing a generic Java type the response should convert to.
      Returns:
      Response entity.
      Throws:
      ApiException - if there are problems with the Api client request.
    • put

      public <T> T put(TypeReference<T> type) throws ApiException
      Build a put request and execute it.
      Type Parameters:
      T - generic response type.
      Parameters:
      type - the TypeReference object representing a generic Java type the response should convert to.
      Returns:
      Response entity.
      Throws:
      ApiException - if there are problems with the Api client request.
    • patch

      public <T> T patch(TypeReference<T> type) throws ApiException
      Build a patch request and execute it.
      Type Parameters:
      T - generic response type.
      Parameters:
      type - the TypeReference object representing a generic Java type the response should convert to.
      Returns:
      Response entity.
      Throws:
      ApiException - if there are problems with the Api client request.
    • delete

      public <T> T delete(TypeReference<T> type) throws ApiException
      Build a delete request and execute it.
      Type Parameters:
      T - generic response type.
      Parameters:
      type - the TypeReference object representing a generic Java type the response should convert to.
      Returns:
      Response entity.
      Throws:
      ApiException - if there are problems with the Api client request.
    • builder

      public static HttpClient.Builder builder(ApiClientBuilderProvider provider)
      Parameters:
      provider - ApiClientBuilderProvider to instantiate the ApiClientBuilder to build a ApiClient.
      Returns:
      builder to build an ApiClient and execute client requests.
    • path

      public HttpClient path(String path)
      Set request path.
      Parameters:
      path - the name of the header.
      Returns:
      the updated instance.
    • header

      public HttpClient header(String key, String value)
      Add an arbitrary header.
      Parameters:
      key - the name of the header.
      value - the value of the header.
      Returns:
      the updated instance.
    • cookie

      public HttpClient cookie(String key, String value)
      Add a cookie to be set.
      Parameters:
      key - the name of the cookie.
      value - the value of the cookie.
      Returns:
      the updated instance.
    • queryParam

      public HttpClient queryParam(String key, String value)
      Add a query parameter.
      Parameters:
      key - the name of the parameter.
      value - the value of the parameter.
      Returns:
      the updated instance.
    • formParam

      public HttpClient formParam(String key, Object value)
      Add a form parameter.
      Parameters:
      key - the name of the parameter.
      value - the value of the parameter.
      Returns:
      the updated instance.
    • body

      public HttpClient body(Object body)
      Add the request body object.
      Parameters:
      body - the body of the request.
      Returns:
      the updated instance.
    • accept

      public HttpClient accept(String accept)
      Add the accepted response media type.
      Parameters:
      accept - accepted response media type.
      Returns:
      the updated instance.
    • contentType

      public HttpClient contentType(String contentType)
      Add the request's Content-Type header.
      Parameters:
      contentType - the request's Content-Type header.
      Returns:
      the updated instance.