Class RequestCycle

java.lang.Object
io.github.grumpystuff.grumpyrest.RequestCycle

public final class RequestCycle extends Object
Holds the run-time state of processing a single request. Application code will normally not have to deal with a request cycle directly, but rather implement a SimpleHandler that takes a Request and returns either a Response, or a value that gets converted to such a response. Only if this scheme is not flexible enough will the application implement a ComplexHandler and deal with the request cycle directly.
  • Constructor Details

    • RequestCycle

      public RequestCycle(RestApi api, jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse, RequestPathSourcingStrategy requestPathSourcingStrategy)
      NOT PUBLIC API
      Parameters:
      api - ...
      servletRequest - ...
      servletResponse - ...
      requestPathSourcingStrategy - ...
  • Method Details

    • getApi

      public RestApi getApi()
      Getter method for the RestApi that handles the request
      Returns:
      the REST API implementation
    • getServletRequest

      public jakarta.servlet.http.HttpServletRequest getServletRequest()
      Getter method for the underlying servlet request
      Returns:
      the servlet request
    • getPathSegments

      public List<String> getPathSegments()
      Getter method for the requested path, split into segments at slashes
      Returns:
      the path segments
    • getMatchedRoute

      public Route getMatchedRoute()
      Getter method for the route that matched this request. This method must not be called before route matching is completed, otherwise it throws an exception.
      Returns:
      the route
    • getPathArguments

      public List<PathArgument> getPathArguments()
      Getter method for the path arguments that are bound to variables in the path of the matched route. This method must not be called before route matching is completed, otherwise it throws an exception.

      The returned list contains elements only for variables in the route's path, not for fixed path segments.

      Returns:
      the path arguments
    • getHighlevelRequest

      public Request getHighlevelRequest()
      The high-level Request object that makes all relevant properties of the HTTP request available. This is the object that gets passed to a SimpleHandler as the only parameter.
      Returns:
      the request
    • getResponseTransmitter

      public ResponseTransmitter getResponseTransmitter()
      Returns an object that is used by Response implementations to transmit the response to the client. It is an abstraction of the HttpServletResponse and contains methods to send headers as well as the response body.

      The returned object is called a response transmitter, even though it abstracts the servlet response, because the latter suffers from bad naming: That object isn't really the response itself as much as a mechanism to send a response to the client.

      Returns:
      the response transmitter