Package io.micronaut.http
Interface HttpResponse<B>
- Type Parameters:
B- The Http body type
- All Superinterfaces:
AttributeHolder,HttpMessage<B>,MutableAttributeHolder
- All Known Subinterfaces:
ByteBodyHttpResponse<B>,MutableHttpResponse<B>
- All Known Implementing Classes:
ByteBodyHttpResponseWrapper,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.ACCEPTEDresponse with an empty body.static <T> MutableHttpResponse<T>Return anHttpStatus.ACCEPTEDresponse with an empty body and aHttpHeaders.LOCATIONheader.static <T> MutableHttpResponse<T>Return anHttpStatus.BAD_REQUESTresponse with an empty body.static <T> MutableHttpResponse<T>badRequest(T body) Return anHttpStatus.BAD_REQUESTresponse with a body.default Bbody()intcode()static <T> MutableHttpResponse<T>Return anHttpStatus.CREATEDresponse with the location of the new resource.static <T> MutableHttpResponse<T>created(T body) Return anHttpStatus.CREATEDresponse with a body.static <T> MutableHttpResponse<T>Return anHttpStatus.CREATEDresponse with a body and the location of the new resource.Helper method for retrieving a single Cookie on a response.default CookiesHelper method for retrieving all Cookies on a response.default HttpStatusheader(@Nullable CharSequence name) Return the first value for the given header or null.static <T> MutableHttpResponse<T>Return anHttpStatus.NO_CONTENTresponse with an empty body.static <T> MutableHttpResponse<T>notAllowed(HttpMethod... allowed) Return anHttpStatus.METHOD_NOT_ALLOWEDresponse with an empty body.static <T> MutableHttpResponse<T>notAllowed(Set<HttpMethod> allowed) Return anHttpStatus.METHOD_NOT_ALLOWEDresponse with an empty body.static <T> MutableHttpResponse<T>notAllowedGeneric(Set<? extends CharSequence> allowed) Return anHttpStatus.METHOD_NOT_ALLOWEDresponse with an empty body.static <T> MutableHttpResponse<T>notFound()Return anHttpStatus.NOT_FOUNDresponse with an empty body.static <T> MutableHttpResponse<T>notFound(T body) Return anHttpStatus.NOT_FOUNDresponse with a body.static <T> MutableHttpResponse<T>Return anHttpStatus.NOT_MODIFIEDresponse with an empty body.static <T> MutableHttpResponse<T>ok()Return anHttpStatus.OKresponse with an empty body.static <T> MutableHttpResponse<T>ok(T body) Return anHttpStatus.OKresponse with a body.static <T> MutableHttpResponse<T>permanentRedirect(URI location) Return anHttpStatus.PERMANENT_REDIRECTresponse with the location of the new resource.reason()static <T> MutableHttpResponse<T>Return anHttpStatus.MOVED_PERMANENTLYresponse with the location of the new resource.static <T> MutableHttpResponse<T>Return anHttpStatus.SEE_OTHERresponse with the location of the new resource.static <T> MutableHttpResponse<T>Return anHttpStatus.INTERNAL_SERVER_ERRORresponse with an empty body.static <T> MutableHttpResponse<T>serverError(T body) Return anHttpStatus.INTERNAL_SERVER_ERRORresponse with a body.default HttpResponse<B>setAttribute(CharSequence name, Object value) Sets an attribute on the message.default HttpStatusstatus()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_REDIRECTresponse with the location of the new resource.default MutableHttpResponse<?>Returns a mutable response based on this response.static <T> MutableHttpResponse<T>Return anHttpStatus.UNAUTHORIZEDresponse with an empty body.static <T> MutableHttpResponse<T>Return anHttpStatus.UNPROCESSABLE_ENTITYresponse with an empty body.static URIuri(CharSequence uri) Helper method for defining URIs.Methods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute, getAttributeMethods inherited from interface io.micronaut.http.HttpMessage
getAttributes, getBody, getBody, getBody, getBody, getBodyWriter, getCharacterEncoding, getContentLength, getContentType, getHeaders, getLocaleMethods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttribute
-
Method Details
-
getStatus
- Returns:
- The current status
To support custom status codes. Use
code()instead ofgetStatus()andHttpStatus.getCode()andreason()instead ofgetStatus()andHttpStatus.getReason()
-
setAttribute
Description copied from interface:MutableAttributeHolderSets an attribute on the message.- Specified by:
setAttributein interfaceHttpMessage<B>- Specified by:
setAttributein 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
To support custom status codes. Use
code()instead ofstatus()andHttpStatus.getCode()andreason()instead ofstatus()andHttpStatus.getReason()
-
code
int code()- Returns:
- The response status code
-
reason
String reason()- Returns:
- The HTTP status reason phrase
-
ok
Return anHttpStatus.OKresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The ok response
-
notFound
Return anHttpStatus.NOT_FOUNDresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
unauthorized
Return anHttpStatus.UNAUTHORIZEDresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
notFound
Return anHttpStatus.NOT_FOUNDresponse with a body.- Type Parameters:
T- The body type- Parameters:
body- The response body- Returns:
- The response
-
badRequest
Return anHttpStatus.BAD_REQUESTresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
badRequest
Return anHttpStatus.BAD_REQUESTresponse with a body.- Type Parameters:
T- The body type- Parameters:
body- The response body- Returns:
- The response
-
unprocessableEntity
Return anHttpStatus.UNPROCESSABLE_ENTITYresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
notAllowed
Return anHttpStatus.METHOD_NOT_ALLOWEDresponse with an empty body.- Type Parameters:
T- The response type- Parameters:
allowed- Allowed Http Methods- Returns:
- The response
-
notAllowed
Return anHttpStatus.METHOD_NOT_ALLOWEDresponse with an empty body.- Type Parameters:
T- The response type- Parameters:
allowed- Allowed Http Methods- Returns:
- The response
-
notAllowedGeneric
Return anHttpStatus.METHOD_NOT_ALLOWEDresponse with an empty body.- Type Parameters:
T- The response type- Parameters:
allowed- Allowed Http Methods- Returns:
- The response
-
serverError
Return anHttpStatus.INTERNAL_SERVER_ERRORresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
serverError
Return anHttpStatus.INTERNAL_SERVER_ERRORresponse with a body.- Type Parameters:
T- The response type- Parameters:
body- The response body- Returns:
- The response
-
accepted
Return anHttpStatus.ACCEPTEDresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
accepted
Return anHttpStatus.ACCEPTEDresponse with an empty body and aHttpHeaders.LOCATIONheader.- 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_CONTENTresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
notModified
Return anHttpStatus.NOT_MODIFIEDresponse with an empty body.- Type Parameters:
T- The response type- Returns:
- The response
-
ok
Return anHttpStatus.OKresponse with a body.- Type Parameters:
T- The body type- Parameters:
body- The response body- Returns:
- The ok response
-
created
Return anHttpStatus.CREATEDresponse with a body.- Type Parameters:
T- The body type- Parameters:
body- The response body- Returns:
- The created response
-
created
Return anHttpStatus.CREATEDresponse 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.CREATEDresponse 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_OTHERresponse 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_REDIRECTresponse 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_REDIRECTresponse 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_PERMANENTLYresponse 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 alternative reason message- Returns:
- The response
-
status
Return a response for the given status.- Type Parameters:
T- The response type- Parameters:
status- The statusreason- An alternative 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
-