Class Response

java.lang.Object
com.soklet.core.Response

@ThreadSafe public class Response extends Object
Represents a logical HTTP response returned by a Resource Method.

Your application's ResponseMarshaler is responsible for taking the Response returned by a Resource Method as input and creating a finalized binary representation (MarshaledResponse), suitable for sending to clients over the wire.

Full documentation is available at https://www.soklet.com/docs/response-writing.

Author:
Mark Allen
  • Method Details

    • withStatusCode

      Acquires a builder for Response instances.
      Parameters:
      statusCode - the HTTP status code for this request (200, 201, etc.)
      Returns:
      the builder
    • withRedirect

      @Nonnull public static Response.Builder withRedirect(@Nonnull RedirectType redirectType, @Nonnull String location)
      Acquires a builder for Response instances that are intended to redirect the client.
      Parameters:
      redirectType - the kind of redirect to perform, for example RedirectType.HTTP_307_TEMPORARY_REDIRECT
      location - the URL to redirect to
      Returns:
      the builder
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • copy

      Vends a mutable copier seeded with this instance's data, suitable for building new instances.
      Returns:
      a copier for this instance
    • getStatusCode

      The HTTP status code to be written to the client for this response.

      See StatusCode for an enumeration of all HTTP status codes.

      Returns:
      the HTTP status code to write to the response
    • getCookies

      The cookies to be written to the client for this response.

      It is possible to send multiple ResponseCookie values with the same name to the client.

      Note that ResponseCookie values, like all response headers, have case-insensitive names per the HTTP spec.

      Returns:
      the cookies to write to the response
    • getHeaders

      The headers to be written to the client for this response.

      The keys are the header names and the values are header values (it is possible to send the client multiple headers with the same name).

      Note that response headers have case-insensitive names per the HTTP spec.

      Returns:
      the headers to write to the response
    • getBody

      The "logical" body content to be written to the response, if present.

      It is the responsibility of the ResponseMarshaler to take this object and convert it into bytes to send over the wire.

      Returns:
      the object representing the response body, or Optional.empty() if no response body should be written