Interface ApiRequest<T>

  • Type Parameters:
    T - The type of the response.

    public interface ApiRequest<T>
    Represents an API request. Can send API requests.
    • Method Detail

      • getResponseClass

        @NotNull
        @NotNull java.lang.Class<T> getResponseClass()
        Gets the Class of the response.
        Returns:
        The Class of the response.
      • getUrl

        @Nullable
        @Nullable java.lang.String getUrl()
        Gets the URL of this ApiRequest.
        Returns:
        The URL of this ApiRequest. If null, the default URL of the WrappedApi will be used.
      • getEndpoint

        @NotNull
        @NotNull java.lang.String getEndpoint()
        Gets the endpoint of this ApiRequest.
        Returns:
        The endpoint of this ApiRequest.
      • getBodyPublisher

        @NonNull
        default java.net.http.HttpRequest.BodyPublisher getBodyPublisher()
        Gets the HttpRequest.BodyPublisher of this ApiRequest.
        Returns:
        The HttpRequest.BodyPublisher of this ApiRequest.
      • getBodyHandler

        @NotNull
        default java.net.http.HttpResponse.BodyHandler<?> getBodyHandler()
        Gets the HttpResponse.BodyHandler of this ApiRequest.
        Returns:
        The HttpResponse.BodyHandler of this ApiRequest.
      • getComputedEndpoint

        default java.lang.String getComputedEndpoint()
        Gets the computed endpoint of this ApiRequest.
        Returns:
        The computed endpoint of this ApiRequest with all PathParameters replaces and RequestQuerys added.
      • applyHeadersToHttpRequestBuilder

        default void applyHeadersToHttpRequestBuilder​(java.net.http.HttpRequest.Builder httpRequestBuilder,
                                                      RequestHeader[] requestHeaders)
        Applies the RequestHeaders to the given HttpRequest.Builder.
        Parameters:
        httpRequestBuilder - The HttpRequest.Builder to apply the RequestHeaders to.
        requestHeaders - The RequestHeaders to apply.
      • createHttpClientInstance

        default java.net.http.HttpClient createHttpClientInstance()
        Creates a new HttpClient instance.
        Returns:
        The created HttpClient instance.
      • createHttpRequestBuilderInstance

        default java.net.http.HttpRequest.Builder createHttpRequestBuilderInstance()
        Creates a new HttpRequest.Builder instance.
        Returns:
        The created HttpRequest.Builder instance.
      • createInstanceOfResponseClass

        default T createInstanceOfResponseClass()
                                         throws java.lang.NoSuchMethodException,
                                                java.lang.reflect.InvocationTargetException,
                                                java.lang.InstantiationException,
                                                java.lang.IllegalAccessException
        Creates a new instance of the response class.
        Returns:
        The created instance of the response class.
        Throws:
        java.lang.NoSuchMethodException - Is thrown if the response class does not have a default constructor.
        java.lang.reflect.InvocationTargetException - Is thrown if the constructor of the response class throws an exception.
        java.lang.InstantiationException - Is thrown if the response class is abstract or interface.
        java.lang.IllegalAccessException - Is thrown if the constructor of the response class is not accessible.
      • handleResponse

        default T handleResponse​(java.net.http.HttpResponse<?> httpResponse)
                          throws java.lang.reflect.InvocationTargetException,
                                 java.lang.NoSuchMethodException,
                                 java.lang.InstantiationException,
                                 java.lang.IllegalAccessException
        Handles the given HttpResponse.
        Parameters:
        httpResponse - The HttpResponse to handle.
        Returns:
        The instance of the response class.
        Throws:
        java.lang.NoSuchMethodException - Is thrown if the response class does not have a default constructor.
        java.lang.reflect.InvocationTargetException - Is thrown if the constructor of the response class throws an exception.
        java.lang.InstantiationException - Is thrown if the response class is abstract or interface.
        java.lang.IllegalAccessException - Is thrown if the constructor of the response class is not accessible.
      • sendAsync

        default java.util.concurrent.CompletableFuture<T> sendAsync()
        Sends the request asynchronously using WrappedApi.runAsync(Runnable).
        Returns:
        A CompletableFuture that will be completed with the instance of response class.
      • send

        default T send()
                throws java.io.IOException,
                       java.lang.InterruptedException,
                       java.lang.reflect.InvocationTargetException,
                       java.lang.NoSuchMethodException,
                       java.lang.InstantiationException,
                       java.lang.IllegalAccessException
        Sends the request synchronously.
        Returns:
        The instance of the response class.
        Throws:
        java.io.IOException - If an I/O error occurs.
        java.lang.InterruptedException - If the operation is interrupted.
        java.lang.NoSuchMethodException - Is thrown if the response class does not have a default constructor.
        java.lang.reflect.InvocationTargetException - Is thrown if the constructor of the response class throws an exception.
        java.lang.InstantiationException - Is thrown if the response class is abstract or interface.
        java.lang.IllegalAccessException - Is thrown if the constructor of the response class is not accessible.