public interface HttpClientContext
The HTTP client context that we use to build and process requests.
HttpClientContext ctx = HttpClientContext.builder()
.baseUrl("http://localhost:8080")
.bodyAdapter(new JacksonBodyAdapter())
.build();
HelloDto dto = ctx.request()
.path("hello")
.queryParam("name", "Rob")
.queryParam("say", "Whats up")
.GET()
.bean(HelloDto.class);
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Builds the HttpClientContext.static interface
Statistic metrics collected to provide an overview of activity of this client. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpClientContext.Builder
builder()
Return the builder to config and build the client context.void
checkResponse
(HttpResponse<?> response) Check the response status code and throw HttpException if the status code is in the error range.Return the body adapter used by the client context.<T> T
Return the http client API implementation.byte[]
decodeContent
(String encoding, byte[] content) Decode the body using the given encoding.byte[]
decodeContent
(HttpResponse<byte[]> httpResponse) Decode the response content given theContent-Encoding
http header.Return the underlying http client.metrics()
Return the current aggregate metrics.metrics
(boolean reset) Return the current metrics with the option of resetting the underlying counters.static HttpClientContext.Builder
Deprecated.readContent
(HttpResponse<byte[]> httpResponse) Return the response content taking into account content encoding.request()
Create a new request.url()
Return a UrlBuilder to use to build an URL taking into account the base URL.
-
Method Details
-
builder
Return the builder to config and build the client context.HttpClientContext ctx = HttpClientContext.builder() .baseUrl("http://localhost:8080") .bodyAdapter(new JacksonBodyAdapter()) .build(); HttpResponse<String> res = ctx.request() .path("hello") .GET().asString();
-
newBuilder
Deprecated.Deprecated - migrate to builder(). -
create
Return the http client API implementation.- Type Parameters:
T
- The service type.- Parameters:
clientInterface
- A@Client
interface with annotated API methods.- Returns:
- The http client API implementation.
-
request
HttpClientRequest request()Create a new request. -
url
UrlBuilder url()Return a UrlBuilder to use to build an URL taking into account the base URL. -
converters
BodyAdapter converters()Return the body adapter used by the client context.This is the body adapter used to convert request and response bodies to java types. For example using Jackson with JSON payloads.
-
httpClient
HttpClient httpClient()Return the underlying http client. -
metrics
HttpClientContext.Metrics metrics()Return the current aggregate metrics.These metrics are collected for all requests sent via this context.
-
metrics
Return the current metrics with the option of resetting the underlying counters.These metrics are collected for all requests sent via this context.
-
checkResponse
Check the response status code and throw HttpException if the status code is in the error range. -
readContent
Return the response content taking into account content encoding.- Parameters:
httpResponse
- The HTTP response to decode the content from- Returns:
- The decoded content
-
decodeContent
Decode the response content given theContent-Encoding
http header.- Parameters:
httpResponse
- The HTTP response- Returns:
- The decoded content
-
decodeContent
Decode the body using the given encoding.- Parameters:
encoding
- The encoding used to decode the contentcontent
- The raw content being decoded- Returns:
- The decoded content
-