Class ApiClient

java.lang.Object
ru.loolzaaa.youkassa.client.ApiClient

public class ApiClient extends Object
Http client for YooKassa API server.

This client use Java 11 HttpClient for communication and Jackson library for request/response body serialization/deserialization respectively.

All requests used authentication routine supplied by authHeaderSupplier with application/json content-type header.

Success status code only 200.

Usually, instance of this class created by ApiClientBuilder.

  • Constructor Details

    • ApiClient

      public ApiClient(String endpoint, Supplier<String> authHeaderSupplier)
      Created ApiClient instance.

      Api endpoint and authentication header supplier must not be null.

      Parameters:
      endpoint - YooKassa API server endpoint
      authHeaderSupplier - authentication header value supplier
  • Method Details

    • sendRequest

      public <T> T sendRequest(String method, String path, Map<String,String> headers, RequestBody body, Class<T> responseClass)
      Invoke execute method and deserialize response for single entity.
      Type Parameters:
      T - type of returned entity
      Parameters:
      method - http method
      path - request path with query params
      headers - additional headers
      body - request body
      responseClass - response type class
      Returns:
      requested deserialized entity
    • sendRequest

      public <T> T sendRequest(String method, String path, Map<String,String> headers, RequestBody body, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
      Invoke execute method and deserialize response for entities collection.
      Type Parameters:
      T - type of returned entity
      Parameters:
      method - http method
      path - request path with query params
      headers - additional headers
      body - request body
      typeReference - jackson type reference for response
      Returns:
      requested deserialized entities collection