Interface HttpResponse<B>

Type Parameters:
B - The Http body type
All Superinterfaces:
AttributeHolder, HttpMessage<B>, MutableAttributeHolder
All Known Subinterfaces:
MutableHttpResponse<B>
All Known Implementing Classes:
FullNettyClientHttpResponse, HttpResponseAdapter, HttpResponseWrapper, NettyMutableHttpResponse

public interface HttpResponse<B> extends HttpMessage<B>

Common interface for HTTP response implementations.

Since:
1.0
Author:
Graeme Rocher
  • Method Details

    • getStatus

      default HttpStatus getStatus()
      Returns:
      The current status
    • setAttribute

      default HttpResponse<B> setAttribute(CharSequence name, Object value)
      Description copied from interface: MutableAttributeHolder
      Sets an attribute on the message.
      Specified by:
      setAttribute in interface HttpMessage<B>
      Specified by:
      setAttribute in interface MutableAttributeHolder
      Parameters:
      name - The name of the attribute
      value - The value of the attribute
      Returns:
      This message
    • header

      Return the first value for the given header or null.
      Parameters:
      name - The name
      Returns:
      The header value
    • body

      @Nullable default B body()
      Returns:
      The body or null
    • status

      default HttpStatus status()
      Returns:
      The HTTP status
    • code

      int code()
      Returns:
      The response status code
    • reason

      String reason()
      Returns:
      The HTTP status reason phrase
    • ok

      static <T> MutableHttpResponse<T> ok()
      Return an HttpStatus.OK response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The ok response
    • notFound

      static <T> MutableHttpResponse<T> notFound()
      Return an HttpStatus.NOT_FOUND response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • unauthorized

      static <T> MutableHttpResponse<T> unauthorized()
      Return an HttpStatus.UNAUTHORIZED response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • notFound

      static <T> MutableHttpResponse<T> notFound(T body)
      Return an HttpStatus.NOT_FOUND response with a body.
      Type Parameters:
      T - The body type
      Parameters:
      body - The response body
      Returns:
      The response
    • badRequest

      static <T> MutableHttpResponse<T> badRequest()
      Return an HttpStatus.BAD_REQUEST response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • badRequest

      static <T> MutableHttpResponse<T> badRequest(T body)
      Return an HttpStatus.BAD_REQUEST response with a body.
      Type Parameters:
      T - The body type
      Parameters:
      body - The response body
      Returns:
      The response
    • unprocessableEntity

      static <T> MutableHttpResponse<T> unprocessableEntity()
      Return an HttpStatus.UNPROCESSABLE_ENTITY response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • notAllowed

      static <T> MutableHttpResponse<T> notAllowed(HttpMethod... allowed)
      Return an HttpStatus.METHOD_NOT_ALLOWED response with an empty body.
      Type Parameters:
      T - The response type
      Parameters:
      allowed - Allowed Http Methods
      Returns:
      The response
    • notAllowed

      static <T> MutableHttpResponse<T> notAllowed(Set<HttpMethod> allowed)
      Return an HttpStatus.METHOD_NOT_ALLOWED response with an empty body.
      Type Parameters:
      T - The response type
      Parameters:
      allowed - Allowed Http Methods
      Returns:
      The response
    • notAllowedGeneric

      static <T> MutableHttpResponse<T> notAllowedGeneric(Set<? extends CharSequence> allowed)
      Return an HttpStatus.METHOD_NOT_ALLOWED response with an empty body.
      Type Parameters:
      T - The response type
      Parameters:
      allowed - Allowed Http Methods
      Returns:
      The response
    • serverError

      static <T> MutableHttpResponse<T> serverError()
      Return an HttpStatus.INTERNAL_SERVER_ERROR response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • serverError

      static <T> MutableHttpResponse<T> serverError(T body)
      Return an HttpStatus.INTERNAL_SERVER_ERROR response with a body.
      Type Parameters:
      T - The response type
      Parameters:
      body - The response body
      Returns:
      The response
    • accepted

      static <T> MutableHttpResponse<T> accepted()
      Return an HttpStatus.ACCEPTED response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • accepted

      static <T> MutableHttpResponse<T> accepted(URI location)
      Return an HttpStatus.ACCEPTED response with an empty body and a HttpHeaders.LOCATION header.
      Type Parameters:
      T - The response type
      Parameters:
      location - the location in which the new resource will be available
      Returns:
      The response
    • noContent

      static <T> MutableHttpResponse<T> noContent()
      Return an HttpStatus.NO_CONTENT response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • notModified

      static <T> MutableHttpResponse<T> notModified()
      Return an HttpStatus.NOT_MODIFIED response with an empty body.
      Type Parameters:
      T - The response type
      Returns:
      The response
    • ok

      static <T> MutableHttpResponse<T> ok(T body)
      Return an HttpStatus.OK response with a body.
      Type Parameters:
      T - The body type
      Parameters:
      body - The response body
      Returns:
      The ok response
    • created

      static <T> MutableHttpResponse<T> created(T body)
      Return an HttpStatus.CREATED response with a body.
      Type Parameters:
      T - The body type
      Parameters:
      body - The response body
      Returns:
      The created response
    • created

      static <T> MutableHttpResponse<T> created(URI location)
      Return an HttpStatus.CREATED response with the location of the new resource.
      Type Parameters:
      T - The response type
      Parameters:
      location - The location of the new resource
      Returns:
      The created response
    • created

      static <T> MutableHttpResponse<T> created(T body, URI location)
      Return an HttpStatus.CREATED response with a body and the location of the new resource.
      Type Parameters:
      T - The body type
      Parameters:
      body - The response body
      location - The location of the new resource
      Returns:
      The created response
    • seeOther

      static <T> MutableHttpResponse<T> seeOther(URI location)
      Return an HttpStatus.SEE_OTHER response with the location of the new resource.
      Type Parameters:
      T - The response type
      Parameters:
      location - The location of the new resource
      Returns:
      The response
    • temporaryRedirect

      static <T> MutableHttpResponse<T> temporaryRedirect(URI location)
      Return an HttpStatus.TEMPORARY_REDIRECT response with the location of the new resource.
      Type Parameters:
      T - The response type
      Parameters:
      location - The location of the new resource
      Returns:
      The response
    • permanentRedirect

      static <T> MutableHttpResponse<T> permanentRedirect(URI location)
      Return an HttpStatus.PERMANENT_REDIRECT response with the location of the new resource.
      Type Parameters:
      T - The response type
      Parameters:
      location - The location of the new resource
      Returns:
      The response
    • redirect

      static <T> MutableHttpResponse<T> redirect(URI location)
      Return an HttpStatus.MOVED_PERMANENTLY response with the location of the new resource.
      Type Parameters:
      T - The response type
      Parameters:
      location - The location of the new resource
      Returns:
      The response
    • status

      static <T> MutableHttpResponse<T> status(HttpStatus status)
      Return a response for the given status.
      Type Parameters:
      T - The response type
      Parameters:
      status - The status
      Returns:
      The response
    • status

      static <T> MutableHttpResponse<T> status(HttpStatus status, String reason)
      Return a response for the given status.
      Type Parameters:
      T - The response type
      Parameters:
      status - The status
      reason - An alternative reason message
      Returns:
      The response
    • status

      static <T> MutableHttpResponse<T> status(int status, String reason)
      Return a response for the given status.
      Type Parameters:
      T - The response type
      Parameters:
      status - The status
      reason - An alternative reason message
      Returns:
      The response
    • uri

      static URI uri(CharSequence uri)
      Helper method for defining URIs. Rethrows checked exceptions as.
      Parameters:
      uri - The URI char sequence
      Returns:
      The URI
    • getCookies

      default Cookies getCookies()
      Helper method for retrieving all Cookies on a response.
      Returns:
      The cookies on the response
    • getCookie

      default Optional<Cookie> getCookie(String name)
      Helper method for retrieving a single Cookie on a response.
      Parameters:
      name - The name of the Cookie
      Returns:
      The Cookie
    • toMutableResponse

      default MutableHttpResponse<?> toMutableResponse()
      Returns a mutable response based on this response.
      Returns:
      the mutable response
      Since:
      4.0.0