Package com.jcabi.http
Interface Response
- All Known Implementing Classes:
DefaultResponse,JacksonResponse,JsonResponse,JsoupResponse,RestResponse,WebLinkingResponse,XmlResponse
@Immutable
public interface Response
RESTful response returned by
Request.fetch().
You can get this response from one of implementations of Request:
Response response = new JdkRequest("https://www.google.com")
.header("Accept", "text/html")
.fetch();
Instances of this interface are immutable and thread-safe.
- Since:
- 0.8
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T extends Response>
TConvert it to another type, by encapsulation.back()Get back to the request it's related to.byte[]binary()Raw body as an array of bytes.body()Get body as a string, assuming it'sUTF-8(if there is something else that can't be translated into a UTF-8 string a runtime exception will be thrown).headers()Get a collection of all headers.reason()Get status line reason phrase.intstatus()Get status of the response as a positive integer number.
-
Method Details
-
back
Request back()Get back to the request it's related to.- Returns:
- The request we're in
-
status
int status()Get status of the response as a positive integer number.- Returns:
- The status code
-
reason
String reason()Get status line reason phrase.- Returns:
- The status line reason phrase
-
headers
Get a collection of all headers.- Returns:
- The headers
-
body
String body()Get body as a string, assuming it'sUTF-8(if there is something else that can't be translated into a UTF-8 string a runtime exception will be thrown).DISCLAIMER: The only encoding supported here is UTF-8. If the body of response contains any chars that can't be used and should be replaced with a "replacement character", a
RuntimeExceptionwill be thrown. If you need to use some other encodings, usebinary()instead.- Returns:
- The body, as a UTF-8 string
-
binary
byte[] binary()Raw body as an array of bytes.- Returns:
- The body, as a UTF-8 string
-
as
Convert it to another type, by encapsulation.- Type Parameters:
T- Type to use- Parameters:
type- Type to use- Returns:
- New response
-