Interface HttpResponse<B>

  • Type Parameters:
    B - The Http body type
    All Superinterfaces:
    io.micronaut.core.attr.AttributeHolder, HttpMessage<B>, io.micronaut.core.attr.MutableAttributeHolder
    All Known Subinterfaces:
    MutableHttpResponse<B>
    All Known Implementing Classes:
    HttpResponseWrapper

    public interface HttpResponse<B>
    extends HttpMessage<B>

    Common interface for HTTP response implementations.

    Since:
    1.0
    • Method Detail

      • getStatus

        HttpStatus getStatus()
        Returns:
        The current status
      • setAttribute

        default HttpResponse<B> setAttribute​(java.lang.CharSequence name,
                                             java.lang.Object value)
        Specified by:
        setAttribute in interface HttpMessage<B>
        Specified by:
        setAttribute in interface io.micronaut.core.attr.MutableAttributeHolder
      • header

        @Nullable
        default java.lang.String header​(@Nullable
                                        java.lang.CharSequence name)
        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

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

        default java.lang.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​(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​(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
      • notAllowedGeneric

        static <T> MutableHttpResponse<T> notAllowedGeneric​(java.util.Set<? extends java.lang.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
      • accepted

        static <T> MutableHttpResponse<T> accepted​(java.net.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
      • 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​(java.net.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,
                                                  java.net.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​(java.net.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​(java.net.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​(java.net.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​(java.net.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,
                                                 java.lang.String reason)
        Return a response for the given status.
        Type Parameters:
        T - The response type
        Parameters:
        status - The status
        reason - An alternatively reason message
        Returns:
        The response
      • uri

        static java.net.URI uri​(java.lang.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 java.util.Optional<Cookie> getCookie​(java.lang.String name)
        Helper method for retrieving a single Cookie on a response.
        Parameters:
        name - The name of the Cookie
        Returns:
        The Cookie