Package io.micronaut.http
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
Common interface for HTTP response implementations.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> MutableHttpResponse<T>
accepted()
Return anHttpStatus.ACCEPTED
response with an empty body.static <T> MutableHttpResponse<T>
Return anHttpStatus.ACCEPTED
response with an empty body and aHttpHeaders.LOCATION
header.static <T> MutableHttpResponse<T>
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()
int
code()
static <T> MutableHttpResponse<T>
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>
Return anHttpStatus.CREATED
response with a body and the location of the new resource.Helper method for retrieving a single Cookie on a response.default Cookies
Helper method for retrieving all Cookies on a response.default HttpStatus
header
(@Nullable CharSequence name) Return the first value for the given header or null.static <T> MutableHttpResponse<T>
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
(Set<HttpMethod> allowed) Return anHttpStatus.METHOD_NOT_ALLOWED
response with an empty body.static <T> MutableHttpResponse<T>
notAllowedGeneric
(Set<? extends 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>
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
(URI location) Return anHttpStatus.PERMANENT_REDIRECT
response with the location of the new resource.reason()
static <T> MutableHttpResponse<T>
Return anHttpStatus.MOVED_PERMANENTLY
response with the location of the new resource.static <T> MutableHttpResponse<T>
Return anHttpStatus.SEE_OTHER
response with the location of the new resource.static <T> MutableHttpResponse<T>
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
(CharSequence name, Object value) Sets an attribute on the message.default HttpStatus
status()
static <T> MutableHttpResponse<T>
Return a response for the given status.static <T> MutableHttpResponse<T>
status
(HttpStatus status) Return a response for the given status.static <T> MutableHttpResponse<T>
status
(HttpStatus status, String reason) Return a response for the given status.static <T> MutableHttpResponse<T>
temporaryRedirect
(URI location) Return anHttpStatus.TEMPORARY_REDIRECT
response with the location of the new resource.default MutableHttpResponse<?>
Returns a mutable response based on this response.static <T> MutableHttpResponse<T>
Return anHttpStatus.UNAUTHORIZED
response with an empty body.static <T> MutableHttpResponse<T>
Return anHttpStatus.UNPROCESSABLE_ENTITY
response with an empty body.static URI
uri
(CharSequence uri) Helper method for defining URIs.Methods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute, getAttribute
Methods inherited from interface io.micronaut.http.HttpMessage
getAttributes, getBody, getBody, getBody, getBody, getBodyWriter, getCharacterEncoding, getContentLength, getContentType, getHeaders, getLocale
Methods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttribute
-
Method Details
-
getStatus
- Returns:
- The current status
-
setAttribute
Description copied from interface:MutableAttributeHolder
Sets an attribute on the message.- Specified by:
setAttribute
in interfaceHttpMessage<B>
- Specified by:
setAttribute
in interfaceMutableAttributeHolder
- Parameters:
name
- The name of the attributevalue
- 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
- Returns:
- The body or null
-
status
- Returns:
- The HTTP status
-
code
int code()- Returns:
- The response status code
-
reason
String reason()- Returns:
- The HTTP status reason phrase
-
ok
Return anHttpStatus.OK
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The ok response
-
notFound
Return anHttpStatus.NOT_FOUND
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
unauthorized
Return anHttpStatus.UNAUTHORIZED
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
notFound
Return anHttpStatus.NOT_FOUND
response with a body.- Type Parameters:
T
- The body type- Parameters:
body
- The response body- Returns:
- The response
-
badRequest
Return anHttpStatus.BAD_REQUEST
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
badRequest
Return anHttpStatus.BAD_REQUEST
response with a body.- Type Parameters:
T
- The body type- Parameters:
body
- The response body- Returns:
- The response
-
unprocessableEntity
Return anHttpStatus.UNPROCESSABLE_ENTITY
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
notAllowed
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
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
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
Return anHttpStatus.INTERNAL_SERVER_ERROR
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
serverError
Return anHttpStatus.INTERNAL_SERVER_ERROR
response with a body.- Type Parameters:
T
- The response type- Parameters:
body
- The response body- Returns:
- The response
-
accepted
Return anHttpStatus.ACCEPTED
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
accepted
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
Return anHttpStatus.NO_CONTENT
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
notModified
Return anHttpStatus.NOT_MODIFIED
response with an empty body.- Type Parameters:
T
- The response type- Returns:
- The response
-
ok
Return anHttpStatus.OK
response with a body.- Type Parameters:
T
- The body type- Parameters:
body
- The response body- Returns:
- The ok response
-
created
Return anHttpStatus.CREATED
response with a body.- Type Parameters:
T
- The body type- Parameters:
body
- The response body- Returns:
- The created response
-
created
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
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
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
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
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
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
Return a response for the given status.- Type Parameters:
T
- The response type- Parameters:
status
- The status- Returns:
- The response
-
status
Return a response for the given status.- Type Parameters:
T
- The response type- Parameters:
status
- The statusreason
- An alternatively reason message- Returns:
- The response
-
status
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
Helper method for defining URIs. Rethrows checked exceptions as.- Parameters:
uri
- The URI char sequence- Returns:
- The URI
-
getCookies
Helper method for retrieving all Cookies on a response.- Returns:
- The cookies on the response
-
getCookie
Helper method for retrieving a single Cookie on a response.- Parameters:
name
- The name of the Cookie- Returns:
- The Cookie
-
toMutableResponse
Returns a mutable response based on this response.- Returns:
- the mutable response
- Since:
- 4.0.0
-