- Enclosing interface:
- HttpClientContext
public static interface HttpClientContext.Builder
Builds the HttpClientContext.
HttpClientContext ctx = HttpClientContext.newBuilder()
.withBaseUrl("http://localhost:8080")
.withBodyAdapter(new JacksonBodyAdapter(new ObjectMapper()))
.build();
HelloDto dto = ctx.request()
.path("hello")
.queryParam("name", "Rob")
.queryParam("say", "Ki ora")
.get()
.bean(HelloDto.class);
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build and return the context.with(HttpClient client)
Set the underlying HttpClient to use.withAuthTokenProvider(AuthTokenProvider authTokenProvider)
Add a Authorization token provider.withBaseUrl(String baseUrl)
Set the base URL to use for requests created from the context.withBodyAdapter(BodyAdapter adapter)
Set the body adapter to use to convert beans to body content and response content back to beans.withCookieHandler(CookieHandler cookieHandler)
Specify a cookie handler to use on the HttpClient.withExecutor(Executor executor)
Specify the Executor to use for asynchronous tasks.withRedirect(HttpClient.Redirect redirect)
Specify the redirect policy.withRequestIntercept(RequestIntercept requestIntercept)
Add a request interceptor.withRequestListener(RequestListener requestListener)
Add a request listener.withRequestTimeout(Duration requestTimeout)
Set the default request timeout.withVersion(HttpClient.Version version)
Specify the HTTP version.
-
Method Details
-
with
Set the underlying HttpClient to use.Used when we wish to control all options of the HttpClient.
-
withBaseUrl
Set the base URL to use for requests created from the context.Note that the base url can be replaced via
HttpClientRequest.url(String)
. -
withRequestTimeout
Set the default request timeout.- See Also:
HttpRequest.Builder.timeout(Duration)
-
withBodyAdapter
Set the body adapter to use to convert beans to body content and response content back to beans. -
withRequestListener
Add a request listener. Note thatRequestLogger
is an implementation for debug logging request/response headers and content. -
withRequestIntercept
Add a request interceptor. -
withAuthTokenProvider
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()).
-
withCookieHandler
Specify a cookie handler to use on the HttpClient. This would override the default cookie handler. -
withRedirect
Specify the redirect policy. Defaults to HttpClient.Redirect.NORMAL. -
withVersion
Specify the HTTP version. Defaults to not set. -
withExecutor
Specify the Executor to use for asynchronous tasks. If not specified a default executor will be used.- See Also:
HttpClient.Builder.executor(Executor)
-
build
HttpClientContext build()Build and return the context.HttpClientContext ctx = HttpClientContext.newBuilder() .withBaseUrl("http://localhost:8080") .withBodyAdapter(new JacksonBodyAdapter(new ObjectMapper())) .build(); HelloDto dto = ctx.request() .path("hello") .queryParam("say", "Ki ora") .get() .bean(HelloDto.class);
-