Interface APIRequest


  • public interface APIRequest
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  APIRequest.Builder  
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default java.net.http.HttpResponse.BodyHandler<?> getBodyHandler()
      This method must return expected API response body.
      Example: You know, that the API will respond with Raw JSON, so you return HttpResponse.BodyHandlers.ofString()
      default java.net.http.HttpRequest.BodyPublisher getBodyPublisher()
      Returns HttpRequest.BodyPublisher with request body.
      Example: You are sending JSON in POST Request, so you pass your JSON into HttpRequest.BodyPublishers.ofString(String) method
      default java.lang.String getContentType()
      Returns value which will be used in Content-Type header.
      @NonNull java.lang.String getEndpoint()
      Returns API endpoint.
      default java.lang.String getFinalEndpoint()
      You should not override this method.
      This method is used for inserting specified queries in getQueries() method
      @NonNull java.lang.String getMethod()
      HTTP Method which will be used for requesting
      Example: GET

      This method is required.
      default PathParameter[] getPathParameters()
      Returns array of PathParameters which will be used for replacing path parameters in APIs endpoint.
      Example: You have /users/{user_id}/stats API endpoint, so you must declare PathParameter with parameter user_id and your desired replacement
      default Query[] getQueries()
      Returns array of Query(ies) which will be added after APIs endpoint.
      Example:
      default void processHttpRequestBuilder​(java.net.http.HttpRequest.Builder httpRequestBuilder)
      This method is called when requesting.
    • Method Detail

      • getEndpoint

        @NonNull
        @NonNull java.lang.String getEndpoint()
        Returns API endpoint. Should start with /
        Example: /users/{user_id}/stats

        This method is required.
        Returns:
        Non-null API Endpoint
      • getMethod

        @NonNull
        @NonNull java.lang.String getMethod()
        HTTP Method which will be used for requesting
        Example: GET

        This method is required.
        Returns:
        HTTP Request method
      • getPathParameters

        default PathParameter[] getPathParameters()
        Returns array of PathParameters which will be used for replacing path parameters in APIs endpoint.
        Example: You have /users/{user_id}/stats API endpoint, so you must declare PathParameter with parameter user_id and your desired replacement
        Returns:
        Nullable PathParameter array
      • getQueries

        default Query[] getQueries()
        Returns array of Query(ies) which will be added after APIs endpoint.
        Example:
             
                return new Query[] {
                    new Query("name", "first_value"),
                    new Query("other_name", "second_value")
                }
             
         

        Which will result in: ?name=first_value&other_name=second_value
        Returns:
        Nullable Query array
      • processHttpRequestBuilder

        default void processHttpRequestBuilder​(@NonNull
                                               java.net.http.HttpRequest.Builder httpRequestBuilder)
        This method is called when requesting. You can specify special headers via HttpRequest.Builder.header(String, String) method.
        Parameters:
        httpRequestBuilder - Non-null HttpRequest.Builder object
      • getBodyHandler

        @NonNull
        default java.net.http.HttpResponse.BodyHandler<?> getBodyHandler()
        This method must return expected API response body.
        Example: You know, that the API will respond with Raw JSON, so you return HttpResponse.BodyHandlers.ofString()
        Returns:
        Non-null HttpResponse.BodyHandler object
      • getContentType

        default java.lang.String getContentType()
        Returns value which will be used in Content-Type header. Null for no Content-Type header
        Returns:
        Content-type
      • getBodyPublisher

        @NonNull
        default java.net.http.HttpRequest.BodyPublisher getBodyPublisher()
        Returns HttpRequest.BodyPublisher with request body.
        Example: You are sending JSON in POST Request, so you pass your JSON into HttpRequest.BodyPublishers.ofString(String) method
        Returns:
        Non-null HttpRequest.BodyPublisher
      • getFinalEndpoint

        default java.lang.String getFinalEndpoint()
        You should not override this method.
        This method is used for inserting specified queries in getQueries() method
        Returns:
        Final API endpoint which will used for requesting