Package org.springframework.http

# 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:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final HttpMethod`
`DELETE`
The HTTP method `DELETE`.
`static final HttpMethod`
`GET`
The HTTP method `GET`.
`static final HttpMethod`
`HEAD`
The HTTP method `HEAD`.
`static final HttpMethod`
`OPTIONS`
The HTTP method `OPTIONS`.
`static final HttpMethod`
`PATCH`
The HTTP method `PATCH`.
`static final HttpMethod`
`POST`
The HTTP method `POST`.
`static final HttpMethod`
`PUT`
The HTTP method `PUT`.
`static final HttpMethod`
`TRACE`
The HTTP method `TRACE`.

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(HttpMethod other)`
`boolean`
`equals(Object other)`
`int`
`hashCode()`
`boolean`
`matches(String method)`
Determine whether this `HttpMethod` matches the given method value.
`String`
`name()`
Return the name of this method, for example, "GET", "POST".
`String`
`toString()`
`static HttpMethod`
`valueOf(String method)`
Return an `HttpMethod` object for the given value.
`static HttpMethod[]`
`values()`
Returns an array containing the standard HTTP methods.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### GET

public static final HttpMethod GET
The HTTP method `GET`.

See Also:
  - HTTP 1.1, section 9.3

### HEAD

public static final HttpMethod HEAD
The HTTP method `HEAD`.

See Also:
  - HTTP 1.1, section 9.4

### POST

public static final HttpMethod POST
The HTTP method `POST`.

See Also:
  - HTTP 1.1, section 9.5

### PUT

public static final HttpMethod PUT
The HTTP method `PUT`.

See Also:
  - HTTP 1.1, section 9.6

### PATCH

public static final HttpMethod PATCH
The HTTP method `PATCH`.

See Also:
  - RFC 5789

### DELETE

public static final HttpMethod DELETE
The HTTP method `DELETE`.

See Also:
  - HTTP 1.1, section 9.7

### OPTIONS

public static final HttpMethod OPTIONS
The HTTP method `OPTIONS`.

See Also:
  - HTTP 1.1, section 9.2

### TRACE

public static final HttpMethod TRACE
The HTTP method `TRACE`.

See Also:
  - HTTP 1.1, section 9.8

## 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`