org.springframework.web.reactive.function.server

Interface ServerRequest

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface and Description
      static interface  ServerRequest.Builder
      Defines a builder for a request.
      static interface  ServerRequest.Headers
      Represents the headers of the HTTP request.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method and Description
      default java.util.Optional<java.lang.Object> attribute(java.lang.String name)
      Get the request attribute value if present.
      java.util.Map<java.lang.String,java.lang.Object> attributes()
      Get a mutable map of request attributes.
      <T> T body(BodyExtractor<T,? super ServerHttpRequest> extractor)
      Extract the body with the given BodyExtractor.
      <T> T body(BodyExtractor<T,? super ServerHttpRequest> extractor, java.util.Map<java.lang.String,java.lang.Object> hints)
      Extract the body with the given BodyExtractor and hints.
      <T> reactor.core.publisher.Flux<T> bodyToFlux(java.lang.Class<? extends T> elementClass)
      Extract the body to a Flux.
      <T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference)
      Extract the body to a Flux.
      <T> reactor.core.publisher.Mono<T> bodyToMono(java.lang.Class<? extends T> elementClass)
      Extract the body to a Mono.
      <T> reactor.core.publisher.Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference)
      Extract the body to a Mono.
      MultiValueMap<java.lang.String,HttpCookie> cookies()
      Get the cookies of this request.
      static ServerRequest create(ServerWebExchange exchange, java.util.List<HttpMessageReader<?>> messageReaders)
      Create a new ServerRequest based on the given ServerWebExchange and message readers.
      ServerWebExchange exchange()
      Get the web exchange that this request is based on.
      reactor.core.publisher.Mono<MultiValueMap<java.lang.String,java.lang.String>> formData()
      Get the form data from the body of the request if the Content-Type is "application/x-www-form-urlencoded" or an empty map otherwise.
      static ServerRequest.Builder from(ServerRequest other)
      Create a builder with the status, headers, and cookies of the given request.
      ServerRequest.Headers headers()
      Get the headers of this request.
      java.util.List<HttpMessageReader<?>> messageReaders()
      Get the readers used to convert the body of this request.
      default HttpMethod method()
      Get the HTTP method.
      java.lang.String methodName()
      Get the name of the HTTP method.
      reactor.core.publisher.Mono<MultiValueMap<java.lang.String,Part>> multipartData()
      Get the parts of a multipart request if the Content-Type is "multipart/form-data" or an empty map otherwise.
      default java.lang.String path()
      Get the request path.
      default PathContainer pathContainer()
      Get the request path as a PathContainer.
      default java.lang.String pathVariable(java.lang.String name)
      Get the path variable with the given name, if present.
      java.util.Map<java.lang.String,java.lang.String> pathVariables()
      Get all path variables for this request.
      reactor.core.publisher.Mono<? extends java.security.Principal> principal()
      Get the authenticated user for the request, if any.
      default java.util.Optional<java.lang.String> queryParam(java.lang.String name)
      Get the first query parameter with the given name, if present.
      MultiValueMap<java.lang.String,java.lang.String> queryParams()
      Get all query parameters for this request.
      java.util.Optional<java.net.InetSocketAddress> remoteAddress()
      Get the remote address to which this request is connected, if available.
      reactor.core.publisher.Mono<WebSession> session()
      Get the web session for this request.
      java.net.URI uri()
      Get the request URI.
      UriBuilder uriBuilder()
      Get a UriBuilderComponents from the URI associated with this ServerRequest.
    • Method Detail

      • method

        @Nullable
        default HttpMethod method()
        Get the HTTP method.
        Returns:
        the HTTP method as an HttpMethod enum value, or null if not resolvable (e.g. in case of a non-standard HTTP method)
      • methodName

        java.lang.String methodName()
        Get the name of the HTTP method.
        Returns:
        the HTTP method as a String
      • uri

        java.net.URI uri()
        Get the request URI.
      • uriBuilder

        UriBuilder uriBuilder()
        Get a UriBuilderComponents from the URI associated with this ServerRequest.

        Note: as of 5.1 this method ignores "Forwarded" and "X-Forwarded-*" headers that specify the client-originated address. Consider using the ForwardedHeaderFilter to extract and use, or to discard such headers.

        Returns:
        a URI builder
      • path

        default java.lang.String path()
        Get the request path.
      • pathContainer

        default PathContainer pathContainer()
        Get the request path as a PathContainer.
      • remoteAddress

        java.util.Optional<java.net.InetSocketAddress> remoteAddress()
        Get the remote address to which this request is connected, if available.
        Since:
        5.1
      • messageReaders

        java.util.List<HttpMessageReader<?>> messageReaders()
        Get the readers used to convert the body of this request.
        Since:
        5.1
      • body

        <T> T body(BodyExtractor<T,? super ServerHttpRequest> extractor)
        Extract the body with the given BodyExtractor.
        Type Parameters:
        T - the type of the body returned
        Parameters:
        extractor - the BodyExtractor that reads from the request
        Returns:
        the extracted body
        See Also:
        body(BodyExtractor, Map)
      • body

        <T> T body(BodyExtractor<T,? super ServerHttpRequest> extractor,
                   java.util.Map<java.lang.String,java.lang.Object> hints)
        Extract the body with the given BodyExtractor and hints.
        Type Parameters:
        T - the type of the body returned
        Parameters:
        extractor - the BodyExtractor that reads from the request
        hints - the map of hints like Jackson2CodecSupport.JSON_VIEW_HINT to use to customize body extraction
        Returns:
        the extracted body
      • bodyToMono

        <T> reactor.core.publisher.Mono<T> bodyToMono(java.lang.Class<? extends T> elementClass)
        Extract the body to a Mono.
        Type Parameters:
        T - the element type
        Parameters:
        elementClass - the class of element in the Mono
        Returns:
        the body as a mono
      • bodyToMono

        <T> reactor.core.publisher.Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference)
        Extract the body to a Mono.
        Type Parameters:
        T - the element type
        Parameters:
        typeReference - a type reference describing the expected response request type
        Returns:
        a mono containing the body of the given type T
      • bodyToFlux

        <T> reactor.core.publisher.Flux<T> bodyToFlux(java.lang.Class<? extends T> elementClass)
        Extract the body to a Flux.
        Type Parameters:
        T - the element type
        Parameters:
        elementClass - the class of element in the Flux
        Returns:
        the body as a flux
      • bodyToFlux

        <T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference)
        Extract the body to a Flux.
        Type Parameters:
        T - the element type
        Parameters:
        typeReference - a type reference describing the expected request body type
        Returns:
        a flux containing the body of the given type T
      • attribute

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

        java.util.Map<java.lang.String,java.lang.Object> attributes()
        Get a mutable map of request attributes.
        Returns:
        the request attributes
      • queryParam

        default java.util.Optional<java.lang.String> queryParam(java.lang.String name)
        Get the first query parameter with the given name, if present.
        Parameters:
        name - the parameter name
        Returns:
        the parameter value
      • queryParams

        MultiValueMap<java.lang.String,java.lang.String> queryParams()
        Get all query parameters for this request.
      • pathVariable

        default java.lang.String pathVariable(java.lang.String name)
        Get the path variable with the given name, if present.
        Parameters:
        name - the variable name
        Returns:
        the variable value
        Throws:
        java.lang.IllegalArgumentException - if there is no path variable with the given name
      • pathVariables

        java.util.Map<java.lang.String,java.lang.String> pathVariables()
        Get all path variables for this request.
      • session

        reactor.core.publisher.Mono<WebSession> session()
        Get the web session for this request.

        Always guaranteed to return an instance either matching the session id requested by the client, or with a new session id either because the client did not specify one or because the underlying session had expired.

        Use of this method does not automatically create a session.

      • principal

        reactor.core.publisher.Mono<? extends java.security.Principal> principal()
        Get the authenticated user for the request, if any.
      • formData

        reactor.core.publisher.Mono<MultiValueMap<java.lang.String,java.lang.String>> formData()
        Get the form data from the body of the request if the Content-Type is "application/x-www-form-urlencoded" or an empty map otherwise.

        Note: calling this method causes the request body to be read and parsed in full, and the resulting MultiValueMap is cached so that this method is safe to call more than once.

      • multipartData

        reactor.core.publisher.Mono<MultiValueMap<java.lang.String,Part>> multipartData()
        Get the parts of a multipart request if the Content-Type is "multipart/form-data" or an empty map otherwise.

        Note: calling this method causes the request body to be read and parsed in full, and the resulting MultiValueMap is cached so that this method is safe to call more than once.

      • exchange

        ServerWebExchange exchange()
        Get the web exchange that this request is based on.

        Note: Manipulating the exchange directly (instead of using the methods provided on ServerRequest and ServerResponse) can lead to irregular results.

        Since:
        5.1
      • create

        static ServerRequest create(ServerWebExchange exchange,
                                    java.util.List<HttpMessageReader<?>> messageReaders)
        Create a new ServerRequest based on the given ServerWebExchange and message readers.
        Parameters:
        exchange - the exchange
        messageReaders - the message readers
        Returns:
        the created ServerRequest
      • from

        static ServerRequest.Builder from(ServerRequest other)
        Create a builder with the status, headers, and cookies of the given request.
        Parameters:
        other - the response to copy the status, headers, and cookies from
        Returns:
        the created builder
        Since:
        5.1