Class Kirara

java.lang.Object
enterprises.iwakura.kirara.core.Kirara
All Implemented Interfaces:
Closeable, AutoCloseable

public abstract class Kirara extends Object implements Closeable
The base class for Kirara library. Extend this class inorder to create a wrapper for a specific API.
You may use createRequest(String, String, Class) for creating API requests.
See Also:
  • Field Details

    • httpCore

      protected final HttpCore httpCore
      The HTTP core used to send requests and receive responses.
    • serializer

      protected final Serializer serializer
      The serializer used to convert objects to and from JSON or other formats.
    • apiUrl

      protected String apiUrl
      The base URL of the API to which requests will be sent. All API request's endpoints will be appended to this URL.
    • defaultRequestHeaders

      protected List<RequestHeader> defaultRequestHeaders
      Default request headers that will be included in every API request. This can be used to set common headers like "User-Agent", "Accept", etc
  • Constructor Details

    • Kirara

      public Kirara(HttpCore httpCore, Serializer serializer)
      Constructs a new Kirara instance with the specified HTTP core and serializer.
      Parameters:
      httpCore - the HTTP core used to send requests
      serializer - the serializer used for request and response bodies
    • Kirara

      public Kirara(HttpCore httpCore, Serializer serializer, String apiUrl)
      Constructs a new Kirara instance with the specified HTTP core, serializer, and API URL.
      Parameters:
      httpCore - the HTTP core used to send requests
      serializer - the serializer used for request and response bodies
      apiUrl - the base URL of the API to which requests will be sent
  • Method Details

    • createRequest

      protected <R extends ApiRequest<T>, T> R createRequest(String method, String endpoint, Class<T> responseClass)
      Constructs a ApiRequest class with the specified method, endpoint, and response class. This method is used to create a request that can be sent to the API.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      T - the type of the response expected from the API
      Parameters:
      method - the HTTP method to use (e.g., "GET", "POST", etc.)
      endpoint - the API endpoint to which the request will be sent
      responseClass - the class of the expected response type
      Returns:
      a new instance of ApiRequest with the specified parameters
    • close

      public void close() throws IOException
      Closes the HTTP core.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs while closing the connection
    • onRequest

      public <T> void onRequest(ApiRequest<T> request)
      Invoked just before sending a request.
      Type Parameters:
      T - the type of the response expected from the API
      Parameters:
      request - the API request being sent
    • onResponse

      public <T> void onResponse(ApiRequest<T> request, T response)
      Invoked when a response is received.
      Type Parameters:
      T - the type of the response expected from the API
      Parameters:
      request - the API request that was sent
      response - the response received from the API
    • onException

      public <T> void onException(ApiRequest<T> request, Throwable exception)
      Invoked when an exception occurs during the request processing or response handling.
      Type Parameters:
      T - the type of the response expected from the API
      Parameters:
      request - the API request that was being processed
      exception - the exception that occurred