Class ApiClient


  • public class ApiClient
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      ApiClient​(java.lang.String endpoint, java.util.function.Supplier<java.lang.String> authHeaderSupplier)
      Created ApiClient instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T sendRequest​(java.lang.String method, java.lang.String path, java.util.Map<java.lang.String,​java.lang.String> headers, RequestBody body, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
      Invoke execute method and deserialize response for entities collection.
      <T> T sendRequest​(java.lang.String method, java.lang.String path, java.util.Map<java.lang.String,​java.lang.String> headers, RequestBody body, java.lang.Class<T> responseClass)
      Invoke execute method and deserialize response for single entity.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ApiClient

        public ApiClient​(java.lang.String endpoint,
                         java.util.function.Supplier<java.lang.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 Detail

      • sendRequest

        public <T> T sendRequest​(java.lang.String method,
                                 java.lang.String path,
                                 java.util.Map<java.lang.String,​java.lang.String> headers,
                                 RequestBody body,
                                 java.lang.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​(java.lang.String method,
                                 java.lang.String path,
                                 java.util.Map<java.lang.String,​java.lang.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