Class HttpRequest


  • public class HttpRequest
    extends Object
    Represents an HTTP request message.

    This class encapsulates the important components of an HTTP request, including the URI, HTTP method, and headers, to provide a structured way to create and use HTTP requests.

    By default, if not specified, the HTTP method is set to GET and no headers are included.

    The HttpHeaders object is used to manage request headers, supporting case-insensitive header names and convenient methods for adding or retrieving header values.

    Since:
    4.0.0
    Author:
    Dmytro Nosan
    • Constructor Detail

      • HttpRequest

        public HttpRequest​(URI uri)
        Creates a new HttpRequest with the specified URI and the default HTTP GET method.
        Parameters:
        uri - the URI of the request
        Throws:
        NullPointerException - if uri is null
      • HttpRequest

        public HttpRequest​(URI uri,
                           String method)
        Creates a new HttpRequest with the specified URI and HTTP method.
        Parameters:
        uri - the URI of the request
        method - the HTTP method of the request (e.g., GET, POST)
        Throws:
        NullPointerException - if uri or method is null
      • HttpRequest

        public HttpRequest​(URI uri,
                           String method,
                           HttpHeaders headers)
        Creates a new HttpRequest with the specified URI, HTTP method, and headers.
        Parameters:
        uri - the URI of the request
        method - the HTTP method of the request (e.g., GET, POST)
        headers - the HTTP headers of the request
        Throws:
        NullPointerException - if uri, method, or headers is null
    • Method Detail

      • getUri

        public URI getUri()
        Returns the URI of the request.
        Returns:
        the URI of the request
      • getMethod

        public String getMethod()
        Returns the HTTP method of the request.

        The method is always returned in uppercase to ensure compatibility with standard HTTP conventions.

        Returns:
        the HTTP method of the request
      • getHeaders

        public HttpHeaders getHeaders()
        Returns the HTTP headers associated with this request.

        The headers are represented as a HttpHeaders object, allowing for easy access and modification of individual headers.

        Returns:
        the HTTP headers of the request
      • toString

        public String toString()
        Returns a string representation of the HTTP request.

        The string representation includes the URI and HTTP method of the request. Headers are not included in this output.

        Overrides:
        toString in class Object
        Returns:
        a string representation of the HTTP request