Enum Class HttpMethod

java.lang.Object
java.lang.Enum<HttpMethod>
de.craftsblock.craftsnet.api.http.HttpMethod
All Implemented Interfaces:
Serializable, Comparable<HttpMethod>, Constable

public enum HttpMethod extends Enum<HttpMethod>
The RequestMethod enum represents the different HTTP request methods, such as POST, GET, PUT, DELETE, PATCH, and HEAD. It also includes the UNKNOWN value for unrecognized methods. The enum provides methods to parse and convert these methods to strings and arrays for use in HTTP request handling.
Since:
1.0.0-SNAPSHOT
See Also:
  • Enum Constant Details

    • CONNECT

      public static final HttpMethod CONNECT
      Represents the CONNECT request method
    • POST

      public static final HttpMethod POST
      Represents the POST request method
    • GET

      public static final HttpMethod GET
      Represents the GET request method
    • PUT

      public static final HttpMethod PUT
      Represents the PUT request method
    • DELETE

      public static final HttpMethod DELETE
      Represents the DELETE request method
    • PATCH

      public static final HttpMethod PATCH
      Represents the PATCH request method
    • OPTIONS

      public static final HttpMethod OPTIONS
      Represents the OPTIONS request method
    • TRACE

      public static final HttpMethod TRACE
      Represents the TRACE request method
    • UNKNOWN

      public static final HttpMethod UNKNOWN
      Represents an unrecognized request method
    • ALL

      public static final HttpMethod ALL
      Represents all request methods
    • ALL_RAW

      public static final HttpMethod ALL_RAW
      Represents all request methods + raw request methods
  • 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
    • getMethods

      public HttpMethod[] getMethods()
      Get the array of strings containing the request methods for this enum value.
      Returns:
      The array of request methods as strings.
    • isRequestBodyAble

      public boolean isRequestBodyAble()
      Check if the HTTP method allows a request body.
      Returns:
      true if the HTTP method allows a request body, otherwise false.
    • isResponseBodyAble

      public boolean isResponseBodyAble()
      Check if the HTTP method allows a response body.
      Returns:
      true if the HTTP method allows a response body, otherwise false.
    • toString

      public String toString()
      Get the string representation of the enum value. For the ALL value, it returns the concatenated string of all methods. For other values, it returns the default string representation of the enum value.
      Overrides:
      toString in class Enum<HttpMethod>
      Returns:
      The string representation of the enum value.
    • parse

      public static HttpMethod parse(String method)
      Parse the given HTTP request method string and return the corresponding RequestMethod enum value. If the method string is not recognized, it returns the UNKNOWN value.
      Parameters:
      method - The HTTP request method as a string.
      Returns:
      The corresponding RequestMethod enum value or UNKNOWN if not recognized.
    • normalize

      public static HttpMethod[] normalize(HttpMethod @NotNull ... methods)
      Normalizes the provided array of HttpMethod values by:
      • Removing null values
      • Excluding UNKNOWN methods
      • Flattening ALL and ALL_RAW into their actual method components
      • Removing duplicates
      Parameters:
      methods - The array of HttpMethod values to normalize
      Returns:
      A normalized array of distinct, valid HttpMethod values
      Since:
      3.4.3-SNAPSHOT
    • join

      public static String join(HttpMethod @NotNull ... methods)
      Joins the names of the provided HttpMethod values using the default delimiter "|". The methods are normalized before joining.
      Parameters:
      methods - The array of HttpMethod values to join.
      Returns:
      A single string of method names separated by the default delimiter.
      Since:
      3.4.3-SNAPSHOT
    • join

      public static String join(@NotNull @NotNull CharSequence delimiter, HttpMethod @NotNull ... methods)
      Joins the names of the provided HttpMethod values into a single string using the specified delimiter. The methods are normalized before joining.
      Parameters:
      delimiter - The string used to separate method names.
      methods - The array of HttpMethod values to join.
      Returns:
      A string of joined method names, or an empty string if methods is null or empty.
      Since:
      3.4.3-SNAPSHOT
    • convert

      @Deprecated(since="3.4.3-SNAPSHOT", forRemoval=true) public static String[] convert(HttpMethod... methods)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Convert an array of RequestMethod enum values to an array of strings representing the request methods. If the array contains the ALL value, it returns all methods as an array. It filters out UNKNOWN and ALL values from the array during conversion.
      Parameters:
      methods - The array of RequestMethod enum values.
      Returns:
      The array of strings representing the request methods.
    • asString

      @Deprecated(since="3.4.3-SNAPSHOT", forRemoval=true) public static String asString(HttpMethod... methods)
      Deprecated, for removal: This API element is subject to removal in a future version.
      in favor of join(HttpMethod...).
      Convert an array of RequestMethod enum values to a single string representation of request methods. The string contains the request methods separated by the "|" character.
      Parameters:
      methods - The array of RequestMethod enum values.
      Returns:
      The string representation of request methods separated by "|".