Class HtmxRequest

java.lang.Object
io.github.wimdeblauwe.htmx.spring.boot.mvc.HtmxRequest

public final class HtmxRequest extends Object
This class can be used as a controller method argument to access the htmx Request Headers.
 
 @GetMapping("/users")
 @HxRequest
 public String users(HtmxRequest htmxRequest) {
     if (htmxRequest.isBoosted()) {
         ...
     }
 }
 
 
See Also:
  • Method Details

    • builder

      public static HtmxRequest.Builder builder()
      Return a HtmxRequest.Builder to create a HtmxRequest.
      Returns:
      the builder
    • empty

      public static HtmxRequest empty()
      Create an empty HtmxRequest.
      Returns:
      the empty HtmxRequest
    • fromRequest

      public static HtmxRequest fromRequest(jakarta.servlet.http.HttpServletRequest request)
      Create a new HtmxRequest from the given HttpServletRequest.
      Parameters:
      request - the request to create the HtmxRequest from
      Returns:
      the HtmxRequest
      Since:
      3.6.0
    • isHtmxRequest

      public boolean isHtmxRequest()
    • isBoosted

      public boolean isBoosted()
      Indicates that the request is via an element using hx-boost.
      Returns:
      true if the request was made via hx-boost, false otherwise
    • getCurrentUrl

      @Nullable public String getCurrentUrl()
      The current URL of the browser when the htmx request was made.
      Returns:
      the URL, or null if the URL was not passed
    • isHistoryRestoreRequest

      public boolean isHistoryRestoreRequest()
      Indicates if the request is for history restoration after a miss in the local history cache
      Returns:
      true if this request is for history restoration, false otherwise
    • getPromptResponse

      @Nullable public String getPromptResponse()
      The user response to an hx-prompt.
      Returns:
      The response of the user. Can be null.
    • getTarget

      @Nullable public String getTarget()
      The id of the target element if it exists.
      Returns:
      the id, or null if no id was passed in the request
    • getTriggerName

      @Nullable public String getTriggerName()
      The name of the triggered element if it exists.
      Returns:
      the name of the trigger, or null if no name was passed in the request
    • getTriggerId

      @Nullable public String getTriggerId()
      The id of the triggered element if it exists.
      Returns:
      the id of the trigger, or null if no name was passed in the request