Class HttpOperations

java.lang.Object
ai.docling.serve.client.operations.HttpOperations
Direct Known Subclasses:
DoclingServeClient

public abstract class HttpOperations extends Object
Abstract base class for HTTP operations. Provides methods for executing HTTP requests such as GET and POST and deserializing responses into specified types. This class is intended to be extended by subclasses that implement these operations for specific use cases.
  • Field Details

    • CONTENT_TYPE_HEADER

      public static final String CONTENT_TYPE_HEADER
      Content-Type header key
      See Also:
    • CONTENT_TYPE_JSON

      public static final String CONTENT_TYPE_JSON
      Content-Type header value for JSON body
      See Also:
    • CONTENT_TYPE_ZIP

      public static final String CONTENT_TYPE_ZIP
      Content-Type header value for ZIP binary body
      See Also:
    • API_KEY_HEADER_NAME

      public static final String API_KEY_HEADER_NAME
      The header name used to specify the API key in HTTP requests. This constant is commonly utilized in authentication mechanisms to include the API key in request headers.
      See Also:
  • Constructor Details

    • HttpOperations

      public HttpOperations()
  • Method Details

    • executeGet

      protected abstract <I, O> O executeGet(RequestContext<I,O> requestContext)
      Executes an HTTP GET request using the details specified in the provided RequestContext.
      Type Parameters:
      I - the type of the request payload
      O - the type of the response object
      Parameters:
      requestContext - the context containing details such as the URI, request payload, and expected response type of the GET operation
      Returns:
      an instance of the response type O, which represents the deserialized response data
    • executeGetWithStreamResponse

      protected abstract <I> StreamResponse executeGetWithStreamResponse(RequestContext<I,StreamResponse> requestContext)
      Executes an HTTP GET request using the details specified in the provided RequestContext.
      Type Parameters:
      I - the type of the request payload
      Parameters:
      requestContext - the context containing details such as the URI, request payload, and expected response type of the GET operation
      Returns:
      an instance of the StreamResponse, which represents the response.
    • executePost

      protected abstract <I, O> O executePost(RequestContext<I,O> requestContext)
      Executes an HTTP POST request using the details provided in the RequestContext. This method is designed to be implemented by subclasses and facilitates sending POST requests with a specified request payload and receiving a deserialized response.
      Type Parameters:
      I - the type of the request payload
      O - the type of the response object
      Parameters:
      requestContext - the context containing details such as the URI, request payload, and expected response type of the POST operation
      Returns:
      an instance of the response type O, which represents the deserialized response data
    • executePostWithStreamResponse

      protected abstract <I> StreamResponse executePostWithStreamResponse(RequestContext<I,StreamResponse> requestContext)
      Executes an HTTP POST request using the details provided in the RequestContext. This method is designed to be implemented by subclasses and facilitates sending POST requests with a specified request payload and receiving a stream response.
      Type Parameters:
      I - the type of the request payload
      Parameters:
      requestContext - the context containing details such as the URI, request payload, and expected response type of the POST operation
      Returns:
      an instance of the StreamResponse, which represents the response.
    • readValue

      protected abstract <T> T readValue(String json, Class<T> valueType)
      Reads and deserializes the given JSON string into an instance of the specified type.
      Type Parameters:
      T - the type of the object to be deserialized
      Parameters:
      json - the JSON string to deserialize; must not be null
      valueType - the Class of the target type; must not be null
      Returns:
      an instance of T deserialized from the provided JSON
      Throws:
      RuntimeException - if the JSON parsing fails