Class HttpMethod

java.lang.Object
org.springframework.http.HttpMethod
All Implemented Interfaces:
Serializable, Comparable<HttpMethod>

public final class HttpMethod extends Object implements Comparable<HttpMethod>, Serializable
Represents an HTTP request method. Intended for use with ClientHttpRequest and RestTemplate.
Since:
3.0
Author:
Arjen Poutsma, Juergen Hoeller, Sam Brannen
See Also:
  • Field Details

  • Method Details

    • values

      public static HttpMethod[] values()
      Returns an array containing the standard HTTP methods. Specifically, this method returns an array containing GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, and TRACE.

      Note that the returned value does not include any HTTP methods defined in WebDav.

    • valueOf

      public static HttpMethod valueOf(String method)
      Return an HttpMethod object for the given value.

      As of Spring Framework 7.1, lookups for predefined constants such as GET are case-insensitive.

      If no predefined constant matches, a new HttpMethod instance is returned for the given value as-is.

      For example, HttpMethod.valueOf("GET") and HttpMethod.valueOf("get") both resolve to GET. Whereas, HttpMethod.valueOf("FOO") and HttpMethod.valueOf("foo") resolve to new HttpMethod("FOO") and new HttpMethod("foo"), respectively. In the latter case, the two resulting HttpMethod instances are not equal and do not match.

      Parameters:
      method - the method value as a String
      Returns:
      the corresponding HttpMethod
    • name

      public String name()
      Return the name of this method, for example, "GET", "POST".
    • matches

      public boolean matches(String method)
      Determine whether this HttpMethod matches the given method value.
      Parameters:
      method - the HTTP method as a String
      Returns:
      true if it matches, false otherwise
      Since:
      4.2.4
    • compareTo

      public int compareTo(HttpMethod other)
      Specified by:
      compareTo in interface Comparable<HttpMethod>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object