Package io.micronaut.http
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 Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <T> MutableHttpResponse<T>
accepted()
Return anHttpStatus.ACCEPTED
response with an empty body.static <T> MutableHttpResponse<T>
accepted(java.net.URI location)
Return anHttpStatus.ACCEPTED
response with an empty body and aHttpHeaders.LOCATION
header.static <T> MutableHttpResponse<T>
badRequest()
Return anHttpStatus.BAD_REQUEST
response with an empty body.static <T> MutableHttpResponse<T>
badRequest(T body)
Return anHttpStatus.BAD_REQUEST
response with a body.default B
body()
default int
code()
static <T> MutableHttpResponse<T>
created(java.net.URI location)
Return anHttpStatus.CREATED
response with the location of the new resource.static <T> MutableHttpResponse<T>
created(T body)
Return anHttpStatus.CREATED
response with a body.static <T> MutableHttpResponse<T>
created(T body, java.net.URI location)
Return anHttpStatus.CREATED
response with a body and the location of the new resource.default java.util.Optional<Cookie>
getCookie(java.lang.String name)
Helper method for retrieving a single Cookie on a response.default Cookies
getCookies()
Helper method for retrieving all Cookies on a response.HttpStatus
getStatus()
default java.lang.String
header(java.lang.CharSequence name)
Return the first value for the given header or null.static <T> MutableHttpResponse<T>
noContent()
Return anHttpStatus.NO_CONTENT
response with an empty body.static <T> MutableHttpResponse<T>
notAllowed(HttpMethod... allowed)
Return anHttpStatus.METHOD_NOT_ALLOWED
response with an empty body.static <T> MutableHttpResponse<T>
notAllowed(java.util.Set<HttpMethod> allowed)
Return anHttpStatus.METHOD_NOT_ALLOWED
response with an empty body.static <T> MutableHttpResponse<T>
notAllowedGeneric(java.util.Set<? extends java.lang.CharSequence> allowed)
Return anHttpStatus.METHOD_NOT_ALLOWED
response with an empty body.static <T> MutableHttpResponse<T>
notFound()
Return anHttpStatus.NOT_FOUND
response with an empty body.static <T> MutableHttpResponse<T>
notFound(T body)
Return anHttpStatus.NOT_FOUND
response with a body.static <T> MutableHttpResponse<T>
notModified()
Return anHttpStatus.NOT_MODIFIED
response with an empty body.static <T> MutableHttpResponse<T>
ok()
Return anHttpStatus.OK
response with an empty body.static <T> MutableHttpResponse<T>
ok(T body)
Return anHttpStatus.OK
response with a body.static <T> MutableHttpResponse<T>
permanentRedirect(java.net.URI location)
Return anHttpStatus.PERMANENT_REDIRECT
response with the location of the new resource.default java.lang.String
reason()
static <T> MutableHttpResponse<T>
redirect(java.net.URI location)
Return anHttpStatus.MOVED_PERMANENTLY
response with the location of the new resource.static <T> MutableHttpResponse<T>
seeOther(java.net.URI location)
Return anHttpStatus.SEE_OTHER
response with the location of the new resource.static <T> MutableHttpResponse<T>
serverError()
Return anHttpStatus.INTERNAL_SERVER_ERROR
response with an empty body.static <T> MutableHttpResponse<T>
serverError(T body)
Return anHttpStatus.INTERNAL_SERVER_ERROR
response with a body.default HttpResponse<B>
setAttribute(java.lang.CharSequence name, java.lang.Object value)
default HttpStatus
status()
static <T> MutableHttpResponse<T>
status(HttpStatus status)
Return a response for the given status.static <T> MutableHttpResponse<T>
status(HttpStatus status, java.lang.String reason)
Return a response for the given status.static <T> MutableHttpResponse<T>
temporaryRedirect(java.net.URI location)
Return anHttpStatus.TEMPORARY_REDIRECT
response with the location of the new resource.static <T> MutableHttpResponse<T>
unauthorized()
Return anHttpStatus.UNAUTHORIZED
response with an empty body.static <T> MutableHttpResponse<T>
unprocessableEntity()
Return anHttpStatus.UNPROCESSABLE_ENTITY
response with an empty body.static java.net.URI
uri(java.lang.CharSequence uri)
Helper method for defining URIs.-
Methods inherited from interface io.micronaut.http.HttpMessage
getAttributes, getBody, getBody, getBody, getCharacterEncoding, getContentLength, getContentType, getHeaders, getLocale
-
-
-
-
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 interfaceHttpMessage<B>
- Specified by:
setAttribute
in interfaceio.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 anHttpStatus.OK
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The ok response
-
notFound
static <T> MutableHttpResponse<T> notFound()
Return anHttpStatus.NOT_FOUND
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
unauthorized
static <T> MutableHttpResponse<T> unauthorized()
Return anHttpStatus.UNAUTHORIZED
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
notFound
static <T> MutableHttpResponse<T> notFound(T body)
Return anHttpStatus.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 anHttpStatus.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 anHttpStatus.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 anHttpStatus.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 anHttpStatus.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(java.util.Set<HttpMethod> allowed)
Return anHttpStatus.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(java.util.Set<? extends java.lang.CharSequence> allowed)
Return anHttpStatus.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 anHttpStatus.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 anHttpStatus.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 anHttpStatus.ACCEPTED
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
accepted
static <T> MutableHttpResponse<T> accepted(java.net.URI location)
Return anHttpStatus.ACCEPTED
response with an empty body and aHttpHeaders.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 anHttpStatus.NO_CONTENT
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
notModified
static <T> MutableHttpResponse<T> notModified()
Return anHttpStatus.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 anHttpStatus.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 anHttpStatus.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 anHttpStatus.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 anHttpStatus.CREATED
response with a body and the location of the new resource.- Type Parameters:
T
- The body type- Parameters:
body
- The response bodylocation
- The location of the new resource- Returns:
- The created response
-
seeOther
static <T> MutableHttpResponse<T> seeOther(java.net.URI location)
Return anHttpStatus.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 anHttpStatus.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 anHttpStatus.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 anHttpStatus.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 statusreason
- 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
-
-