Enum Class HttpMethod

java.lang.Object
java.lang.Enum<HttpMethod>
cloud.opencode.base.web.http.HttpMethod
All Implemented Interfaces:
Serializable, Comparable<HttpMethod>, Constable

public enum HttpMethod extends Enum<HttpMethod>
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:
  • Enum Constant Details

    • GET

      public static final HttpMethod GET
      GET - Retrieve resource GET - 获取资源
    • POST

      public static final HttpMethod POST
      POST - Create resource POST - 创建资源
    • PUT

      public static final HttpMethod PUT
      PUT - Replace resource PUT - 替换资源
    • DELETE

      public static final HttpMethod DELETE
      DELETE - Delete resource DELETE - 删除资源
    • PATCH

      public static final HttpMethod PATCH
      PATCH - Partial update PATCH - 部分更新
    • OPTIONS

      public static final HttpMethod OPTIONS
      OPTIONS - Get supported methods OPTIONS - 获取支持的方法
    • TRACE

      public static final HttpMethod TRACE
      TRACE - Echo request TRACE - 回显请求
    • CONNECT

      public static final HttpMethod CONNECT
      CONNECT - Establish tunnel CONNECT - 建立隧道
  • Method Details

    • values

      public static HttpMethod[] 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

      public static HttpMethod valueOf(String name)
      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 name
      NullPointerException - 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

      public static HttpMethod fromString(String method)
      Parses method name to enum. 解析方法名称为枚举。
      Parameters:
      method - the method name - 方法名称
      Returns:
      the HttpMethod - HTTP 方法
      Throws:
      IllegalArgumentException - if method is invalid - 如果方法无效
    • isValid

      public static boolean isValid(String method)