Class HttpRequest

java.lang.Object
de.oliver.fancyanalytics.sdk.utils.HttpRequest

public class HttpRequest extends Object
  • Constructor Details

    • HttpRequest

      public HttpRequest(String url, String method, Object body, Map<String,String> headers)
      Constructs a new HttpRequest with the provided URL, method, body, and headers.
      Parameters:
      url - The URL to which the request is directed.
      method - The HTTP method to use (e.g., GET, POST).
      body - The body of the request. This can be any object that needs to be sent in the request body.
      headers - A map representing the headers to be included in the request, where the key is the header name and the value is the header value.
    • HttpRequest

      public HttpRequest(String url)
  • Method Details

    • send

      Sends an HTTP request based on preset configuration including URL, method, body, and headers.
      Returns:
      the HttpResponse containing the response as a string from the executed HTTP request.
      Throws:
      URISyntaxException - if the URL is not properly formatted.
      IOException - if an I/O error occurs when sending or receiving.
      InterruptedException - if the operation is interrupted.
    • getUrl

      public String getUrl()
    • getMethod

      public String getMethod()
    • withMethod

      public HttpRequest withMethod(String method)
      Sets the method of the request.
      Parameters:
      method - The method to use.
      Returns:
      The HttpRequest.
    • getBody

      public Object getBody()
    • withBody

      public HttpRequest withBody(Object body)
      Sets the body of the request.
      Parameters:
      body - The body of the request.
      Returns:
      The HttpRequest.
    • getHeaders

      public Map<String,String> getHeaders()
    • withHeaders

      public HttpRequest withHeaders(Map<String,String> headers)
      Sets the headers of the request.
      Parameters:
      headers - The headers of the request.
      Returns:
      The HttpRequest.
    • withHeader

      public HttpRequest withHeader(String key, String value)
      Adds a header to the request.
      Parameters:
      key - The key of the header.
      value - The value of the header.
      Returns:
      The HttpRequest.
    • getTimeout

      public Duration getTimeout()
    • withTimeout

      public HttpRequest withTimeout(Duration timeout)
      Sets the timeout of the request.
      Parameters:
      timeout - The timeout of the request.
      Returns:
      The HttpRequest.