Interface ClientRequest


public interface ClientRequest
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.

Since:
5.0
Author:
Brian Clozel, Arjen Poutsma
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Defines a builder for a request.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of attribute whose value can be used to correlate log messages for this request.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Optional<Object>
    Return the request attribute value if present.
    Return the attributes of this request.
    BodyInserter<?,? super org.springframework.http.client.reactive.ClientHttpRequest>
    Return the body inserter of this request.
    org.springframework.util.MultiValueMap<String,String>
    Return the cookies of this request.
    create(org.springframework.http.HttpMethod method, URI url)
    Create a request builder with the given HTTP method and url.
    Create a builder initialized with the HTTP method, url, headers, cookies, attributes, and body of the given request.
    org.springframework.http.HttpHeaders
    Return the headers of this request.
    Consumer<org.springframework.http.client.reactive.ClientHttpRequest>
    Return consumer(s) configured to access to the ClientHttpRequest.
    Return a log message prefix to use to correlate messages for this request.
    org.springframework.http.HttpMethod
    Return the HTTP method.
    method(org.springframework.http.HttpMethod method, URI url)
    Deprecated.
    url()
    Return the request URI.
    reactor.core.publisher.Mono<Void>
    writeTo(org.springframework.http.client.reactive.ClientHttpRequest request, ExchangeStrategies strategies)
    Write this request to the given ClientHttpRequest.
  • Field Details

    • LOG_ID_ATTRIBUTE

      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:
  • Method Details

    • method

      org.springframework.http.HttpMethod method()
      Return the HTTP method.
    • url

      URI url()
      Return the request URI.
    • headers

      org.springframework.http.HttpHeaders headers()
      Return the headers of this request.
    • cookies

      org.springframework.util.MultiValueMap<String,String> cookies()
      Return the cookies of this request.
    • body

      BodyInserter<?,? super org.springframework.http.client.reactive.ClientHttpRequest> body()
      Return the body inserter of this request.
    • attribute

      default Optional<Object> attribute(String name)
      Return the request attribute value if present.
      Parameters:
      name - the attribute name
      Returns:
      the attribute value
    • attributes

      Map<String,Object> attributes()
      Return the attributes of this request.
    • httpRequest

      @Nullable Consumer<org.springframework.http.client.reactive.ClientHttpRequest> httpRequest()
      Return consumer(s) configured to access to the ClientHttpRequest.
      Since:
      5.3
    • logPrefix

      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:
      the log message prefix or an empty String if the LOG_ID_ATTRIBUTE is not set.
      Since:
      5.1
    • writeTo

      reactor.core.publisher.Mono<Void> writeTo(org.springframework.http.client.reactive.ClientHttpRequest request, ExchangeStrategies strategies)
      Write this request to the given ClientHttpRequest.
      Parameters:
      request - the client http request to write to
      strategies - the strategies to use when writing
      Returns:
      Mono<Void> to indicate when writing is complete
    • from

      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 - the request to copy from
      Returns:
      the builder instance
    • method

      @Deprecated static ClientRequest.Builder method(org.springframework.http.HttpMethod method, URI url)
      Deprecated.
      Create a builder with the given HTTP method and url.
      Parameters:
      method - the HTTP method (GET, POST, etc)
      url - the url (as a URI instance)
      Returns:
      the created builder
    • create

      static ClientRequest.Builder create(org.springframework.http.HttpMethod method, URI url)
      Create a request builder with the given HTTP method and url.
      Parameters:
      method - the HTTP method (GET, POST, etc)
      url - the url (as a URI instance)
      Returns:
      the created builder