Class RequestPredicates

java.lang.Object
org.springframework.web.reactive.function.server.RequestPredicates

public abstract class RequestPredicates extends Object
Implementations of RequestPredicate that implement various useful request matching operations, such as matching based on path, HTTP method, etc.
Since:
5.0
Author:
Arjen Poutsma
  • Nested Class Summary Link icon

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Receives notifications from the logical structure of request predicates.
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
     
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    accept(MediaType... mediaTypes)
    Return a RequestPredicate that tests if the request's accept header is compatible with any of the given media types.
    all()
    Return a RequestPredicate that always matches.
    contentType(MediaType... mediaTypes)
    Return a RequestPredicate that tests if the request's content type is included by any of the given media types.
    DELETE(String pattern)
    Return a RequestPredicate that matches if request's HTTP method is DELETE and the given pattern matches against the request path.
    GET(String pattern)
    Return a RequestPredicate that matches if request's HTTP method is GET and the given pattern matches against the request path.
    HEAD(String pattern)
    Return a RequestPredicate that matches if request's HTTP method is HEAD and the given pattern matches against the request path.
    Return a RequestPredicate that tests the request's headers against the given headers predicate.
    method(HttpMethod httpMethod)
    Return a RequestPredicate that matches if the request's HTTP method is equal to the given method.
    methods(HttpMethod... httpMethods)
    Return a RequestPredicate that matches if the request's HTTP method is equal to one the of the given methods.
    OPTIONS(String pattern)
    Return a RequestPredicate that matches if request's HTTP method is OPTIONS and the given pattern matches against the request path.
    PATCH(String pattern)
    Return a RequestPredicate that matches if request's HTTP method is PATCH and the given pattern matches against the request path.
    path(String pattern)
    Return a RequestPredicate that tests the request path against the given path pattern.
    pathExtension(String extension)
    Deprecated, for removal: This API element is subject to removal in a future version.
    without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers).
    pathExtension(Predicate<String> extensionPredicate)
    Deprecated, for removal: This API element is subject to removal in a future version.
    without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers).
    Return a function that creates new path-matching RequestPredicates from pattern Strings using the given PathPatternParser.
    POST(String pattern)
    Return a RequestPredicate that matches if request's HTTP method is POST and the given pattern matches against the request path.
    PUT(String pattern)
    Return a RequestPredicate that matches if request's HTTP method is PUT and the given pattern matches against the request path.
    queryParam(String name, String value)
    Return a RequestPredicate that matches if the request's query parameter of the given name has the given value.
    queryParam(String name, Predicate<String> predicate)
    Return a RequestPredicate that tests the request's query parameter of the given name against the given predicate.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details Link icon

    • RequestPredicates Link icon

      public RequestPredicates()
  • Method Details Link icon

    • all Link icon

      public static RequestPredicate all()
      Return a RequestPredicate that always matches.
      Returns:
      a predicate that always matches
    • method Link icon

      public static RequestPredicate method(HttpMethod httpMethod)
      Return a RequestPredicate that matches if the request's HTTP method is equal to the given method.
      Parameters:
      httpMethod - the HTTP method to match against
      Returns:
      a predicate that tests against the given HTTP method
    • methods Link icon

      public static RequestPredicate methods(HttpMethod... httpMethods)
      Return a RequestPredicate that matches if the request's HTTP method is equal to one the of the given methods.
      Parameters:
      httpMethods - the HTTP methods to match against
      Returns:
      a predicate that tests against the given HTTP methods
      Since:
      5.1
    • path Link icon

      public static RequestPredicate path(String pattern)
      Return a RequestPredicate that tests the request path against the given path pattern.
      Parameters:
      pattern - the pattern to match to
      Returns:
      a predicate that tests against the given path pattern
      See Also:
    • pathPredicates Link icon

      public static Function<String, RequestPredicate> pathPredicates(PathPatternParser patternParser)
      Return a function that creates new path-matching RequestPredicates from pattern Strings using the given PathPatternParser.

      This method can be used to specify a non-default, customized PathPatternParser when resolving path patterns.

      Parameters:
      patternParser - the parser used to parse patterns given to the returned function
      Returns:
      a function that resolves a pattern String into a path-matching RequestPredicates instance
    • headers Link icon

      public static RequestPredicate headers(Predicate<ServerRequest.Headers> headersPredicate)
      Return a RequestPredicate that tests the request's headers against the given headers predicate.
      Parameters:
      headersPredicate - a predicate that tests against the request headers
      Returns:
      a predicate that tests against the given header predicate
    • contentType Link icon

      public static RequestPredicate contentType(MediaType... mediaTypes)
      Return a RequestPredicate that tests if the request's content type is included by any of the given media types.
      Parameters:
      mediaTypes - the media types to match the request's content type against
      Returns:
      a predicate that tests the request's content type against the given media types
    • accept Link icon

      public static RequestPredicate accept(MediaType... mediaTypes)
      Return a RequestPredicate that tests if the request's accept header is compatible with any of the given media types.
      Parameters:
      mediaTypes - the media types to match the request's accept header against
      Returns:
      a predicate that tests the request's accept header against the given media types
    • GET Link icon

      public static RequestPredicate GET(String pattern)
      Return a RequestPredicate that matches if request's HTTP method is GET and the given pattern matches against the request path.
      Parameters:
      pattern - the path pattern to match against
      Returns:
      a predicate that matches if the request method is GET and if the given pattern matches against the request path
      See Also:
    • HEAD Link icon

      public static RequestPredicate HEAD(String pattern)
      Return a RequestPredicate that matches if request's HTTP method is HEAD and the given pattern matches against the request path.
      Parameters:
      pattern - the path pattern to match against
      Returns:
      a predicate that matches if the request method is HEAD and if the given pattern matches against the request path
      See Also:
    • POST Link icon

      public static RequestPredicate POST(String pattern)
      Return a RequestPredicate that matches if request's HTTP method is POST and the given pattern matches against the request path.
      Parameters:
      pattern - the path pattern to match against
      Returns:
      a predicate that matches if the request method is POST and if the given pattern matches against the request path
      See Also:
    • PUT Link icon

      public static RequestPredicate PUT(String pattern)
      Return a RequestPredicate that matches if request's HTTP method is PUT and the given pattern matches against the request path.
      Parameters:
      pattern - the path pattern to match against
      Returns:
      a predicate that matches if the request method is PUT and if the given pattern matches against the request path
      See Also:
    • PATCH Link icon

      public static RequestPredicate PATCH(String pattern)
      Return a RequestPredicate that matches if request's HTTP method is PATCH and the given pattern matches against the request path.
      Parameters:
      pattern - the path pattern to match against
      Returns:
      a predicate that matches if the request method is PATCH and if the given pattern matches against the request path
      See Also:
    • DELETE Link icon

      public static RequestPredicate DELETE(String pattern)
      Return a RequestPredicate that matches if request's HTTP method is DELETE and the given pattern matches against the request path.
      Parameters:
      pattern - the path pattern to match against
      Returns:
      a predicate that matches if the request method is DELETE and if the given pattern matches against the request path
      See Also:
    • OPTIONS Link icon

      public static RequestPredicate OPTIONS(String pattern)
      Return a RequestPredicate that matches if request's HTTP method is OPTIONS and the given pattern matches against the request path.
      Parameters:
      pattern - the path pattern to match against
      Returns:
      a predicate that matches if the request method is OPTIONS and if the given pattern matches against the request path
      See Also:
    • pathExtension Link icon

      @Deprecated(since="7.0", forRemoval=true) public static RequestPredicate pathExtension(String extension)
      Deprecated, for removal: This API element is subject to removal in a future version.
      without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers). For further context, please read issue #24179
      Return a RequestPredicate that matches if the request's path has the given extension.
      Parameters:
      extension - the path extension to match against, ignoring case
      Returns:
      a predicate that matches if the request's path has the given file extension
    • pathExtension Link icon

      @Deprecated(since="7.0", forRemoval=true) public static RequestPredicate pathExtension(Predicate<String> extensionPredicate)
      Deprecated, for removal: This API element is subject to removal in a future version.
      without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers). For further context, please read issue #24179
      Return a RequestPredicate that matches if the request's path matches the given predicate.
      Parameters:
      extensionPredicate - the predicate to test against the request path extension
      Returns:
      a predicate that matches if the given predicate matches against the request's path file extension
    • queryParam Link icon

      public static RequestPredicate queryParam(String name, String value)
      Return a RequestPredicate that matches if the request's query parameter of the given name has the given value.
      Parameters:
      name - the name of the query parameter to test against
      value - the value of the query parameter to test against
      Returns:
      a predicate that matches if the query parameter has the given value
      Since:
      5.0.7
      See Also:
    • queryParam Link icon

      public static RequestPredicate queryParam(String name, Predicate<String> predicate)
      Return a RequestPredicate that tests the request's query parameter of the given name against the given predicate.
      Parameters:
      name - the name of the query parameter to test against
      predicate - the predicate to test against the query parameter value
      Returns:
      a predicate that matches the given predicate against the query parameter of the given name
      See Also: