Class HtmxRequest
java.lang.Object
io.github.wimdeblauwe.htmx.spring.boot.mvc.HtmxRequest
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:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic HtmxRequest.Builder
builder()
Return aHtmxRequest.Builder
to create aHtmxRequest
.static HtmxRequest
empty()
Create an emptyHtmxRequest
.static HtmxRequest
fromRequest
(jakarta.servlet.http.HttpServletRequest request) Create a newHtmxRequest
from the givenHttpServletRequest
.The current URL of the browser when the htmx request was made.The user response to an hx-prompt.The id of the target element if it exists.The id of the triggered element if it exists.The name of the triggered element if it exists.boolean
Indicates that the request is via an element using hx-boost.boolean
Indicates if the request is for history restoration after a miss in the local history cacheboolean
-
Method Details
-
builder
Return aHtmxRequest.Builder
to create aHtmxRequest
.- Returns:
- the builder
-
empty
Create an emptyHtmxRequest
.- Returns:
- the empty HtmxRequest
-
fromRequest
Create a newHtmxRequest
from the givenHttpServletRequest
.- 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
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
The user response to an hx-prompt.- Returns:
- The response of the user. Can be null.
-
getTarget
The id of the target element if it exists.- Returns:
- the id, or null if no id was passed in the request
-
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
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
-