Enum Class HttpMethod
- All Implemented Interfaces:
Serializable, Comparable<HttpMethod>, Constable
HTTP Method - HTTP Request Method Enumeration
HTTP 方法 - HTTP 请求方法枚举
This enum defines standard HTTP methods as specified in RFC 7231 and RFC 5789.
此枚举定义了 RFC 7231 和 RFC 5789 中规定的标准 HTTP 方法。
Example | 示例:
HttpMethod method = HttpMethod.GET;
boolean hasBody = method.hasRequestBody();
boolean safe = method.isSafe();
Features | 主要功能:
- Standard HTTP method enumeration - 标准HTTP方法枚举
- Idempotent and safe method metadata - 幂等和安全方法元数据
- Request body indicator - 请求体指示器
Usage Examples | 使用示例:
HttpMethod method = HttpMethod.GET;
boolean safe = method.isSafe(); // true
boolean hasBody = method.hasRequestBody(); // false
HttpMethod parsed = HttpMethod.fromString("POST");
Security | 安全性:
- Thread-safe: Yes (enum is immutable) - 是(枚举是不可变的)
- Null-safe: No (fromString throws on null) - 否(fromString对null抛出异常)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionCONNECT - Establish tunnel CONNECT - 建立隧道DELETE - Delete resource DELETE - 删除资源GET - Retrieve resource GET - 获取资源HEAD - Get headers only HEAD - 仅获取头部OPTIONS - Get supported methods OPTIONS - 获取支持的方法PATCH - Partial update PATCH - 部分更新POST - Create resource POST - 创建资源PUT - Replace resource PUT - 替换资源TRACE - Echo request TRACE - 回显请求 -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpMethodfromString(String method) Parses method name to enum.booleanChecks if this method typically has a request body.booleanChecks if this method is idempotent (same request produces same result).booleanisSafe()Checks if this method is safe (no side effects).static booleanstatic HttpMethodReturns the enum constant of this class with the specified name.static HttpMethod[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
GET
GET - Retrieve resource GET - 获取资源 -
POST
POST - Create resource POST - 创建资源 -
PUT
PUT - Replace resource PUT - 替换资源 -
DELETE
DELETE - Delete resource DELETE - 删除资源 -
PATCH
PATCH - Partial update PATCH - 部分更新 -
HEAD
HEAD - Get headers only HEAD - 仅获取头部 -
OPTIONS
OPTIONS - Get supported methods OPTIONS - 获取支持的方法 -
TRACE
TRACE - Echo request TRACE - 回显请求 -
CONNECT
CONNECT - Establish tunnel CONNECT - 建立隧道
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
hasRequestBody
public boolean hasRequestBody()Checks if this method typically has a request body. 检查此方法是否通常有请求体。- Returns:
- true if has body - 如果有请求体返回 true
-
isIdempotent
public boolean isIdempotent()Checks if this method is idempotent (same request produces same result). 检查此方法是否是幂等的(相同请求产生相同结果)。- Returns:
- true if idempotent - 如果幂等返回 true
-
isSafe
public boolean isSafe()Checks if this method is safe (no side effects). 检查此方法是否安全(无副作用)。- Returns:
- true if safe - 如果安全返回 true
-
fromString
Parses method name to enum. 解析方法名称为枚举。- Parameters:
method- the method name - 方法名称- Returns:
- the HttpMethod - HTTP 方法
- Throws:
IllegalArgumentException- if method is invalid - 如果方法无效
-
isValid
-