Class ApiRequest<T>

java.lang.Object
enterprises.iwakura.kirara.core.ApiRequest<T>
Type Parameters:
T - the type of the response expected from the API

public class ApiRequest<T> extends Object
Represents an API request in Kirara. This class encapsulates the details of an API request, including the HTTP method, URL, endpoint, response class, headers, path parameters, request queries, and body. It provides methods to set these details and compute the final request URL.
  • Field Details

    • kirara

      protected final Kirara kirara
      Kirara instance associated with this request.
    • method

      protected final String method
      The HTTP method for this request (e.g., "GET", "POST").
    • endpoint

      protected final String endpoint
      The API endpoint to which the request will be sent. This is a relative path that will be appended to the base URL. If url is null, the default API URL from Kirara will be used. If that will be null as well, the endpoint will be used as the full URL.
    • responseClass

      protected final Class<T> responseClass
      The class of the expected response type. This is used to deserialize the response body into the appropriate type.
    • url

      protected String url
      The base URL for the API. If null, the default API URL from Kirara will be used. If that is also null, the endpoint will be used as the full URL.
    • headers

      protected List<RequestHeader> headers
      The headers to be included in this API request. This can be null, in which case no headers will be set.
    • pathParameters

      protected Set<PathParameter> pathParameters
      The path parameters to be included in this API request. This can be null, in which case no path parameters will be set.
    • requestQueries

      protected Set<RequestQuery> requestQueries
      The request queries to be included in this API request. This can be null, in which case no request queries will be set.
    • body

      protected Object body
      The body of this API request. This can be null, in which case no body will be set. It is typically used for requests that require a payload, such as POST or PUT requests.
  • Constructor Details

    • ApiRequest

      public ApiRequest(Kirara kirara, String method, String url, String endpoint, Class<T> responseClass)
      Constructs an ApiRequest with the specified parameters.
      Parameters:
      kirara - the Kirara instance associated with this request
      method - the HTTP method (e.g., "GET", "POST")
      url - the base URL for the API, can be null to use the default API URL
      endpoint - the API endpoint to which the request will be sent
      responseClass - the class of the expected response type
  • Method Details

    • withUrl

      public <R extends ApiRequest<T>> R withUrl(String url)
      Sets the URL for this API request.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      url - the URL to set for this request. If null, the default API URL from Kirara will be used.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • withExplicitHeaders

      public <R extends ApiRequest<T>> R withExplicitHeaders(List<RequestHeader> headers)
      Sets headers for this API requests, discarding any previously set headers.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      headers - the list of headers to set for this request. If null, no headers will be set.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • withExplicitPathParameters

      public <R extends ApiRequest<T>> R withExplicitPathParameters(Set<PathParameter> pathParameters)
      Sets path parameters for this API request, discarding any previously set path parameters.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      pathParameters - the set of path parameters to set for this request. If null, no path parameters will be set.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • withExplicitRequestQueries

      public <R extends ApiRequest<T>> R withExplicitRequestQueries(Set<RequestQuery> requestQueries)
      Sets request queries for this API request, discarding any previously set request queries.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      requestQueries - the set of request queries to set for this request. If null, no request queries will be set.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • withHeader

      public <R extends ApiRequest<T>> R withHeader(RequestHeader header)
      Adds a request header to this API request. If headers were previously set, this method appends the new header to the existing list or creates a new list if none exists.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      header - the request header to add to this API request.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • withPathParameter

      public <R extends ApiRequest<T>> R withPathParameter(PathParameter pathParameter)
      Adds a path parameter to this API request. If path parameters were previously set, this method appends the new parameter to the existing set or creates a new set if none exists.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      pathParameter - the path parameter to add to this API request.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • withRequestQuery

      public <R extends ApiRequest<T>> R withRequestQuery(RequestQuery requestQuery)
      Adds a request query to this API request. If request queries were previously set, this method appends the new query to the existing set or creates a new set if none exists.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      requestQuery - the request query to add to this API request.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • withBody

      public <R extends ApiRequest<T>> R withBody(Object body)
      Sets the body of this API request. This method can be used to set the body for requests that require a payload, such as POST or PUT requests.
      Type Parameters:
      R - the type of the request, extending ApiRequest
      Parameters:
      body - the body to set for this request. If null, no body will be set.
      Returns:
      a reference to this ApiRequest, allowing for method chaining.
    • computeRequestUrl

      public String computeRequestUrl()
      Computes the request URL for this API request.
      Returns:
      the constructed request URL as a String.
    • send

      public CompletableFuture<T> send()
      Invokes HttpCore.send(ApiRequest) on the current Kirara instance.
      Returns:
      A CompletableFuture that will complete with the response of type T.