Top Description Inners Fields Methods
org.springframework.web.reactive.function.client

public Interface ClientRequest

Known Direct Implementers
org.springframework.web.reactive.function.client.DefaultClientRequestBuilder.BodyInserterRequest
Imports
java.net.URI, java.util.Map, .Optional, java.util.function.Consumer, org.reactivestreams.Publisher, reactor.core.publisher.Mono, org.springframework.core.ParameterizedTypeReference, org.springframework.http.HttpHeaders, .HttpMethod, org.springframework.http.client.reactive.ClientHttpRequest, org.springframework.lang.Nullable, org.springframework.util.MultiValueMap, org.springframework.web.reactive.function.BodyInserter

Represents a typed, immutable, client-side HTTP request, as executed by the ExchangeFunction. Instances of this interface can be created via static builder methods.

Note that applications are more likely to perform requests through WebClient rather than using this directly.

Authors
Brian Clozel, Arjen Poutsma
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ClientRequest.Builder

Defines a builder for a request.

Field Summary

Modifier and TypeField and Description
public static final String
LOG_ID_ATTRIBUTE

Name of attribute whose value can be used to correlate log messages for this request.

Method Summary

Modifier and TypeMethod and Description
public default Optional<Object>

Returns:

the attribute value
attribute
(String
the attribute name
name
)

Return the request attribute value if present.

public Map<String, Object>
attributes()

Return the attributes of this request.

public BodyInserter<?, ? super ClientHttpRequest>
body()

Return the body inserter of this request.

public MultiValueMap<String, String>
cookies()

Return the cookies of this request.

public static ClientRequest.Builder

Returns:

the created builder
create
(HttpMethod
the HTTP method (GET, POST, etc)
method
,
URI
the url (as a URI instance)
url
)

Create a request builder with the given HTTP method and url.

public static ClientRequest.Builder

Returns:

the builder instance
from
(ClientRequest
the request to copy from
other
)

Create a builder initialized with the HTTP method, url, headers, cookies, attributes, and body of the given request.

public HttpHeaders
headers()

Return the headers of this request.

public Consumer<ClientHttpRequest>
httpRequest()

Return consumer(s) configured to access to the ClientHttpRequest.

public String

Returns:

the log message prefix or an empty String if the LOG_ID_ATTRIBUTE is not set.
logPrefix
()

Return a log message prefix to use to correlate messages for this request.

public HttpMethod
method()

Return the HTTP method.

public static ClientRequest.Builder

Returns:

the created builder
method
(HttpMethod
the HTTP method (GET, POST, etc)
method
,
URI
the url (as a URI instance)
url
)
Deprecated in favor of create(HttpMethod, URI)

Create a builder with the given HTTP method and url.

public URI
url()

Return the request URI.

public Mono<Void>

Returns:

Mono<Void> to indicate when writing is complete
writeTo
(ClientHttpRequest
the client http request to write to
request
,
ExchangeStrategies
the strategies to use when writing
strategies
)

Write this request to the given ClientHttpRequest.

Field Detail

LOG_ID_ATTRIBUTEback to summary
public static final String LOG_ID_ATTRIBUTE

Name of attribute whose value can be used to correlate log messages for this request. Use logPrefix() to obtain a consistently formatted prefix based on this attribute.

Since
5.1
See Also
logPrefix()

Method Detail

attributeback to summary
public default Optional<Object> attribute(String name)

Return the request attribute value if present.

Parameters
name:String

the attribute name

Returns:Optional<Object>

the attribute value

attributesback to summary
public Map<String, Object> attributes()

Return the attributes of this request.

bodyback to summary
public BodyInserter<?, ? super ClientHttpRequest> body()

Return the body inserter of this request.

cookiesback to summary
public MultiValueMap<String, String> cookies()

Return the cookies of this request.

createback to summary
public static ClientRequest.Builder create(HttpMethod method, URI url)

Create a request builder with the given HTTP method and url.

Parameters
method:HttpMethod

the HTTP method (GET, POST, etc)

url:URI

the url (as a URI instance)

Returns:ClientRequest.Builder

the created builder

fromback to summary
public static ClientRequest.Builder from(ClientRequest other)

Create a builder initialized with the HTTP method, url, headers, cookies, attributes, and body of the given request.

Parameters
other:ClientRequest

the request to copy from

Returns:ClientRequest.Builder

the builder instance

headersback to summary
public HttpHeaders headers()

Return the headers of this request.

httpRequestback to summary
public Consumer<ClientHttpRequest> httpRequest()

Return consumer(s) configured to access to the ClientHttpRequest.

Annotations
@Nullable
Since
5.3
logPrefixback to summary
public String logPrefix()

Return a log message prefix to use to correlate messages for this request. The prefix is based on the value of the attribute LOG_ID_ATTRIBUTE surrounded with "[" and "]".

Returns:String

the log message prefix or an empty String if the LOG_ID_ATTRIBUTE is not set.

Since
5.1
methodback to summary
public HttpMethod method()

Return the HTTP method.

methodback to summary
public static ClientRequest.Builder method(HttpMethod method, URI url)

Deprecated

in favor of create(HttpMethod, URI)

Create a builder with the given HTTP method and url.

Parameters
method:HttpMethod

the HTTP method (GET, POST, etc)

url:URI

the url (as a URI instance)

Returns:ClientRequest.Builder

the created builder

Annotations
@Deprecated
urlback to summary
public URI url()

Return the request URI.

writeToback to summary
public Mono<Void> writeTo(ClientHttpRequest request, ExchangeStrategies strategies)

Write this request to the given ClientHttpRequest.

Parameters
request:ClientHttpRequest

the client http request to write to

strategies:ExchangeStrategies

the strategies to use when writing

Returns:Mono<Void>

Mono<Void> to indicate when writing is complete

org.springframework.web.reactive.function.client back to summary

public Interface ClientRequest.Builder

Known Direct Implementers
org.springframework.web.reactive.function.client.DefaultClientRequestBuilder

Defines a builder for a request.

Method Summary

Modifier and TypeMethod and Description
public ClientRequest.Builder

Returns:

this builder
attribute
(String
the name of the attribute to add
name
,
Object
the value of the attribute to add
value
)

Set the attribute with the given name to the given value.

public ClientRequest.Builder

Returns:

this builder
attributes
(Consumer<Map<String, Object>>
a function that consumes the attributes
attributesConsumer
)

Manipulate the request attributes with the given consumer.

public ClientRequest.Builder

Returns:

this builder
body
(BodyInserter<?, ? super ClientHttpRequest>
the BodyInserter that writes to the request
inserter
)

Set the body of the request to the given BodyInserter.

public <
the type of the elements contained in the publisher
S
,
the type of the Publisher
P extends Publisher<S>
>
ClientRequest.Builder

Returns:

the built request
body
(P
the Publisher to write to the request
publisher
,
Class<S>
the class of elements contained in the publisher
elementClass
)

Set the body of the request to the given Publisher and return it.

public <
the type of the elements contained in the publisher
S
,
the type of the Publisher
P extends Publisher<S>
>
ClientRequest.Builder

Returns:

the built request
body
(P
the Publisher to write to the request
publisher
,
ParameterizedTypeReference<S>
a type reference describing the elements contained in the publisher
typeReference
)

Set the body of the request to the given Publisher and return it.

public ClientRequest
build()

Build the request.

public ClientRequest.Builder

Returns:

this builder
cookie
(String
the cookie name
name
,
String...
the cookie value(s)
values
)

Add a cookie with the given name and value(s).

public ClientRequest.Builder

Returns:

this builder
cookies
(Consumer<MultiValueMap<String, String>>
a function that consumes the cookies map
cookiesConsumer
)

Manipulate this request's cookies with the given consumer.

public ClientRequest.Builder

Returns:

this builder
header
(String
the header name
headerName
,
String...
the header value(s)
headerValues
)

Add the given header value(s) under the given name.

public ClientRequest.Builder

Returns:

this builder
headers
(Consumer<HttpHeaders>
a function that consumes the HttpHeaders
headersConsumer
)

Manipulate this request's headers with the given consumer.

public ClientRequest.Builder

Returns:

this builder
httpRequest
(Consumer<ClientHttpRequest>
a consumer to access the ClientHttpRequest with
requestConsumer
)

Callback for access to the ClientHttpRequest that in turn provides access to the native request of the underlying HTTP library.

public ClientRequest.Builder

Returns:

this builder
method
(HttpMethod
the new method
method
)

Set the method of the request.

public ClientRequest.Builder

Returns:

this builder
url
(URI
the new url
url
)

Set the url of the request.

Method Detail

attributeback to summary
public ClientRequest.Builder attribute(String name, Object value)

Set the attribute with the given name to the given value.

Parameters
name:String

the name of the attribute to add

value:Object

the value of the attribute to add

Returns:ClientRequest.Builder

this builder

attributesback to summary
public ClientRequest.Builder attributes(Consumer<Map<String, Object>> attributesConsumer)

Manipulate the request attributes with the given consumer. The attributes provided to the consumer are "live", so that the consumer can be used to inspect attributes, remove attributes, or use any of the other map-provided methods.

Parameters
attributesConsumer:Consumer<Map<String, Object>>

a function that consumes the attributes

Returns:ClientRequest.Builder

this builder

bodyback to summary
public ClientRequest.Builder body(BodyInserter<?, ? super ClientHttpRequest> inserter)

Set the body of the request to the given BodyInserter.

Parameters
inserter:BodyInserter<?, ? super ClientHttpRequest>

the BodyInserter that writes to the request

Returns:ClientRequest.Builder

this builder

bodyback to summary
public <S, P extends Publisher<S>> ClientRequest.Builder body(P publisher, Class<S> elementClass)

Set the body of the request to the given Publisher and return it.

Parameters
<S>
the type of the elements contained in the publisher
<P>
the type of the Publisher
publisher:P

the Publisher to write to the request

elementClass:Class<S>

the class of elements contained in the publisher

Returns:ClientRequest.Builder

the built request

bodyback to summary
public <S, P extends Publisher<S>> ClientRequest.Builder body(P publisher, ParameterizedTypeReference<S> typeReference)

Set the body of the request to the given Publisher and return it.

Parameters
<S>
the type of the elements contained in the publisher
<P>
the type of the Publisher
publisher:P

the Publisher to write to the request

typeReference:ParameterizedTypeReference<S>

a type reference describing the elements contained in the publisher

Returns:ClientRequest.Builder

the built request

buildback to summary
public ClientRequest build()

Build the request.

cookieback to summary
public ClientRequest.Builder cookie(String name, String... values)

Add a cookie with the given name and value(s).

Parameters
name:String

the cookie name

values:String[]

the cookie value(s)

Returns:ClientRequest.Builder

this builder

cookiesback to summary
public ClientRequest.Builder cookies(Consumer<MultiValueMap<String, String>> cookiesConsumer)

Manipulate this request's cookies with the given consumer. The map provided to the consumer is "live", so that the consumer can be used to overwrite existing cookie values, remove cookies, or use any of the other MultiValueMap methods.

Parameters
cookiesConsumer:Consumer<MultiValueMap<String, String>>

a function that consumes the cookies map

Returns:ClientRequest.Builder

this builder

headerback to summary
public ClientRequest.Builder header(String headerName, String... headerValues)

Add the given header value(s) under the given name.

Parameters
headerName:String

the header name

headerValues:String[]

the header value(s)

Returns:ClientRequest.Builder

this builder

See Also
HttpHeaders#add(String, String)
headersback to summary
public ClientRequest.Builder headers(Consumer<HttpHeaders> headersConsumer)

Manipulate this request's headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the other HttpHeaders methods.

Parameters
headersConsumer:Consumer<HttpHeaders>

a function that consumes the HttpHeaders

Returns:ClientRequest.Builder

this builder

httpRequestback to summary
public ClientRequest.Builder httpRequest(Consumer<ClientHttpRequest> requestConsumer)

Callback for access to the ClientHttpRequest that in turn provides access to the native request of the underlying HTTP library. This could be useful for setting advanced, per-request options that exposed by the underlying library.

Parameters
requestConsumer:Consumer<ClientHttpRequest>

a consumer to access the ClientHttpRequest with

Returns:ClientRequest.Builder

this builder

Since
5.3
methodback to summary
public ClientRequest.Builder method(HttpMethod method)

Set the method of the request.

Parameters
method:HttpMethod

the new method

Returns:ClientRequest.Builder

this builder

Since
5.0.1
urlback to summary
public ClientRequest.Builder url(URI url)

Set the url of the request.

Parameters
url:URI

the new url

Returns:ClientRequest.Builder

this builder

Since
5.0.1