Class WebRequest
java.lang.Object
io.fluxzero.sdk.common.Message
io.fluxzero.sdk.web.WebRequest
- All Implemented Interfaces:
HasMetadata, HasMessage
Represents a web request message within the Fluxzero Runtime.
This message is routed to handlers using annotations like HandleWeb, HandleGet, or
HandleSocketOpen.
WebRequest extends Message and includes additional metadata such as:
path– the requested URI path including query parametersmethod– HTTP or WebSocket method (e.g. GET, WS_OPEN)headers– structured request headerscookies– parsed from the Cookie header
It also provides a fluent WebRequest.Builder API to construct requests programmatically.
Example Usage
WebRequest request = WebRequest.post("https://api.example.com/projects")
.body(new ProjectDetails("My Project", "My Description"))
.build();
Outbound requests with an absolute URL that are dispatched using the WebRequestGateway will be forwarded
by the proxy in Fluxzero Runtime.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from interface HasMessage
warnedAboutMissingPropertyFields inherited from interface HasMetadata
FINAL_CHUNK -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new WebRequest instance using the provided Message. -
Method Summary
Modifier and TypeMethodDescriptionaddMetadata(Metadata metadata) Returns a new message with the combined metadata.addMetadata(Object... keyValues) Adds multiple metadata entries.addMetadata(String key, Object value) Adds a single metadata entry.addMetadata(Map<String, ?> values) Adds metadata from a given map.Attaches a user object to the metadata using the configuredUserProvider.static WebRequest.Builderbuilder()Creates a newWebRequest.Builderinstance for constructing aWebRequest.static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aDELETE requestto given url.static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aGET requestto given url.Returns the content type of the request (based onContent-Typeheader).static Optional<HttpCookie> Retrieves the first cookie with the given name from the provided Metadata object.Finds a cookie by name.Retrieves the first header value for the given name from the provided Metadata object.Returns a single header value, ornullif not present.The HTTP headers as a case-sensitive map.getHeaders(Metadata metadata) Retrieves a case-insensitive map of headers from the provided Metadata object.getHeaders(String name) Returns all values for the specified header.@NonNull StringThe HTTP or WebSocket method (e.g.static StringExtracts the HTTP or WebSocket method (e.g., "GET", "POST", "WS_OPEN") from the provided Metadata object.@NonNull StringgetPath()The request path including query parameters (e.g.<R> RgetPayloadAs(Type type) Deserializes the payload into a given type, using JSON if content type isapplication/json.static StringgetSocketSessionId(Metadata metadata) Retrieves the WebSocket session ID from the provided metadata, ornullif it is missing.static StringExtracts the request path from the provided Metadata object.static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aPATCH requestto given url.static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aPOST requestto given url.static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aPUT requestto given url.static StringrequireSocketSessionId(Metadata metadata) Retrieves the WebSocket session ID from the provided metadata or throws an exception if it is missing.serialize(Serializer serializer) Serializes the request using the content type if applicable.Creates a mutable builder for this request.withMessageId(String messageId) withMetadata(Metadata metadata) withPayload(Object payload) Returns a new message instance with the provided payload and existing metadata, ID, and timestamp.withTimestamp(Instant timestamp) Methods inherited from class Message
asMessage, getPayload, toMessageMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HasMessage
computeRoutingKey, getMessageId, getPayloadClass, getRoutingKey, getRoutingKey, getTimestampMethods inherited from interface HasMetadata
chunked, getMetadata, lastChunk
-
Field Details
-
urlKey
- See Also:
-
methodKey
- See Also:
-
headersKey
- See Also:
-
sessionIdKey
- See Also:
-
-
Constructor Details
-
WebRequest
Constructs a new WebRequest instance using the provided Message.- Parameters:
m- the Message instance containing the payload, metadata, message ID, and timestamp
-
-
Method Details
-
builder
Creates a newWebRequest.Builderinstance for constructing aWebRequest. -
get
Creates a newWebRequest.Builderinstance for constructing aGET requestto given url. -
post
Creates a newWebRequest.Builderinstance for constructing aPOST requestto given url. -
put
Creates a newWebRequest.Builderinstance for constructing aPUT requestto given url. -
patch
Creates a newWebRequest.Builderinstance for constructing aPATCH requestto given url. -
delete
Creates a newWebRequest.Builderinstance for constructing aDELETE requestto given url. -
serialize
Serializes the request using the content type if applicable. -
withMetadata
-
addMetadata
Description copied from class:MessageReturns a new message with the combined metadata.- Overrides:
addMetadatain classMessage
-
addMetadata
Description copied from class:MessageAdds a single metadata entry.- Overrides:
addMetadatain classMessage
-
addMetadata
Description copied from class:MessageAdds multiple metadata entries.- Overrides:
addMetadatain classMessage
-
addMetadata
Description copied from class:MessageAdds metadata from a given map.- Overrides:
addMetadatain classMessage
-
addUser
Description copied from class:MessageAttaches a user object to the metadata using the configuredUserProvider. -
withPayload
Description copied from class:MessageReturns a new message instance with the provided payload and existing metadata, ID, and timestamp.- Overrides:
withPayloadin classMessage
-
withMessageId
-
withTimestamp
-
getHeader
-
getHeaders
-
getContentType
Returns the content type of the request (based onContent-Typeheader). -
getPayloadAs
Deserializes the payload into a given type, using JSON if content type isapplication/json.- Type Parameters:
R- the expected payload type- Parameters:
type- the target type- Returns:
- deserialized payload
-
getCookie
Finds a cookie by name.- Parameters:
name- the cookie name- Returns:
- optional cookie
-
getPath
The request path including query parameters (e.g."/api/users?id=123"). May contain the full URL for outbound web requests. -
getMethod
The HTTP or WebSocket method (e.g."GET","POST","WS_OPEN"). -
getHeaders
-
toBuilder
Creates a mutable builder for this request. -
getUrl
Extracts the request path from the provided Metadata object.- Parameters:
metadata- the metadata object containing the request path information- Returns:
- the request path as a string
- Throws:
IllegalStateException- if the request path information is missing in the metadata
-
getMethod
Extracts the HTTP or WebSocket method (e.g., "GET", "POST", "WS_OPEN") from the provided Metadata object.- Parameters:
metadata- the metadata object containing the method information- Returns:
- the HTTP or WebSocket method as a string
- Throws:
IllegalStateException- if the method information is missing in the metadata
-
getHeaders
-
getHeader
-
getCookie
Retrieves the first cookie with the given name from the provided Metadata object. -
getSocketSessionId
-
requireSocketSessionId
-