- Enclosing interface:
HttpClient
HttpClient client = HttpClient.builder()
.baseUrl("http://localhost:8080")
.bodyAdapter(new JacksonBodyAdapter())
.build();
HelloDto dto = client.request()
.path("hello")
.queryParam("name", "Rob")
.queryParam("say", "Whats up")
.GET()
.bean(HelloDto.class);
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
The state of the builder with methods to read the set state. -
Method Summary
Modifier and TypeMethodDescriptionauthenticator
(Authenticator authenticator) Set a HttpClient authenticator to the underlyingHttpClient
.authTokenProvider
(AuthTokenProvider authTokenProvider) Add a Authorization token provider.Set the base URL to use for requests created from the context.bodyAdapter
(BodyAdapter adapter) Set the body adapter to use to convert beans to body content and response content back to beans.build()
Build and return the context.client
(HttpClient client) Set the underlying HttpClient to use.configureWith
(io.avaje.inject.BeanScope beanScope) Configure BodyAdapter and RetryHandler using dependency injection BeanScope.connectionTimeout
(Duration connectionTimeout) Set the connection timeout to use.cookieHandler
(CookieHandler cookieHandler) Specify a cookie handler to use on the HttpClient.Specify the Executor to use for asynchronous tasks.globalErrorMapper
(Function<HttpException, RuntimeException> errorMapper) Set the default mapper to be used to transformHttpException
into a different kind of exception.priority
(int priority) Set the priority for HTTP/2 requests to the underlyingHttpClient
.proxy
(ProxySelector proxySelector) Set the proxy to the underlyingHttpClient
.redirect
(HttpClient.Redirect redirect) Specify the redirect policy.requestIntercept
(RequestIntercept... requestIntercept) Add a request interceptor.requestListener
(RequestListener... requestListener) Add a request listener.requestLogging
(boolean requestLogging) Disable or enable built in request and response logging.requestTimeout
(Duration requestTimeout) Set the default request timeout.retryHandler
(RetryHandler retryHandler) Set a RetryHandler to use to retry requests.sslContext
(SSLContext sslContext) Set the sslContext to the underlyingHttpClient
.sslParameters
(SSLParameters sslParameters) Set the sslParameters to the underlyingHttpClient
.state()
Return the state of the builder.version
(HttpClient.Version version) Specify the HTTP version.
-
Method Details
-
baseUrl
Set the base URL to use for requests created from the context.Note that the base url can be replaced via
HttpClientRequest.url(String)
. -
globalErrorMapper
Set the default mapper to be used to transformHttpException
into a different kind of exception. Individual requests can override with their own mapper.When set, all
HttpException
that are thrown by this client will be caught and rethrown with the given function by default.- Parameters:
errorMapper
- The function to map the httpException- Returns:
- The request being built
-
connectionTimeout
Set the connection timeout to use.- See Also:
-
requestTimeout
Set the default request timeout.- See Also:
-
bodyAdapter
Set the body adapter to use to convert beans to body content and response content back to beans. -
retryHandler
Set a RetryHandler to use to retry requests. -
requestLogging
Disable or enable built in request and response logging.By default request logging is enabled. Set this to false to stop the default
RequestLogger
being registered to log request and response headers and bodies etc.With logging level set to
DEBUG
forio.avaje.http.client.RequestLogger
the request and response are logged as a summary with response status and time.Set the logging level to
TRACE
to include the request and response headers and body payloads with truncation for large bodies.Suppression
We can also use
HttpClientRequest.suppressLogging()
to suppress logging on specific requests.Logging of Authorization headers is suppressed.
AuthTokenProvider
requests are suppressed.- Parameters:
requestLogging
- Disable/enable the registration of the default logger- See Also:
-
requestListener
Add a request listener. Multiple listeners may be added, when do so they will process events in the order they were added.Note that
RequestLogger
is an implementation for debug logging request/response headers and content which is registered by default depending onrequestLogging(boolean)
.- See Also:
-
requestIntercept
Add a request interceptor. Multiple interceptors may be added. -
authTokenProvider
Add a Authorization token provider.When set all requests are expected to use a Authorization Bearer token unless they are marked via
HttpClientRequest.skipAuthToken()
.The AuthTokenProvider obtains a new token typically with an expiry. This is automatically called as needed and the Authorization Bearer header set on all requests (not marked with skipAuthToken()).
-
client
Set the underlying HttpClient to use.Used when we wish to control all options of the HttpClient.
-
cookieHandler
Specify a cookie handler to use on the HttpClient. This would override the default cookie handler.- See Also:
-
redirect
Specify the redirect policy. Defaults to HttpClient.Redirect.NORMAL.- See Also:
-
version
Specify the HTTP version. Defaults to not set.- See Also:
-
executor
Specify the Executor to use for asynchronous tasks. If not specified a default executor will be used.- See Also:
-
proxy
Set the proxy to the underlyingHttpClient
.- See Also:
-
sslContext
Set the sslContext to the underlyingHttpClient
.- See Also:
-
sslParameters
Set the sslParameters to the underlyingHttpClient
.- See Also:
-
authenticator
Set a HttpClient authenticator to the underlyingHttpClient
.- See Also:
-
priority
Set the priority for HTTP/2 requests to the underlyingHttpClient
.- See Also:
-
configureWith
Configure BodyAdapter and RetryHandler using dependency injection BeanScope. -
state
HttpClient.Builder.State state()Return the state of the builder. -
build
HttpClient build()Build and return the context.HttpClient client = HttpClient.builder() .baseUrl("http://localhost:8080") .bodyAdapter(new JacksonBodyAdapter()) .build(); HelloDto dto = client.request() .path("hello") .queryParam("say", "Whats up") .GET() .bean(HelloDto.class);
-