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
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.

      Note that this lookup is case-sensitive. For predefined constants, the method value must be provided in uppercase (e.g., "GET", "POST"). If no predefined constant matches, a new HttpMethod instance is returned for the given value as-is. For example, HttpMethod.valueOf("GET") resolves to GET, while HttpMethod.valueOf("get") resolves to new HttpMethod("get"), and 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