Record Class HttpResponse

java.lang.Object
java.lang.Record
org.teleight.teleightbots.webhook.HttpResponse

public record HttpResponse(@NotNull HttpResponse.StatusCode statusCode, @NotNull String body) extends Record
Represents an HTTP response used to respond to a webhook request.
  • Constructor Details

    • HttpResponse

      public HttpResponse(@NotNull @NotNull HttpResponse.StatusCode statusCode, @NotNull @NotNull String body)
      Creates an instance of a HttpResponse record class.
      Parameters:
      statusCode - the value for the statusCode record component
      body - the value for the body record component
  • Method Details

    • ok

      public static HttpResponse ok(@NotNull @NotNull String responseBody)
      Creates an HTTP response with status code 200 (OK) and the specified response body.
      Parameters:
      responseBody - The body of the response. Cannot be null.
      Returns:
      An HttpResponse with status code 200 (OK).
    • error

      public static HttpResponse error(@NotNull @NotNull String responseBody)
      Creates an HTTP response with status code 500 (Internal Server Error) and the specified response body.
      Parameters:
      responseBody - The body of the response. Cannot be null.
      Returns:
      An HttpResponse with status code 500 (Internal Server Error).
    • noContent

      public static HttpResponse noContent()
      Creates an HTTP response with status code 204 (No Content) and an empty body.
      Returns:
      An HttpResponse with status code 204 (No Content).
    • response

      public static HttpResponse response(@NotNull @NotNull HttpResponse.StatusCode statusCode, @NotNull @NotNull String responseBody)
      Creates an HTTP response with the specified status code and response body.
      Parameters:
      statusCode - The status code of the response. Cannot be null.
      responseBody - The body of the response. Cannot be null.
      Returns:
      An HttpResponse with the specified status code and response body.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • statusCode

      @NotNull public @NotNull HttpResponse.StatusCode statusCode()
      Returns the value of the statusCode record component.
      Returns:
      the value of the statusCode record component
    • body

      @NotNull public @NotNull String body()
      Returns the value of the body record component.
      Returns:
      the value of the body record component