Largely wraps the standard JDK HttpRequest with additional support for converting beans to body content and converting beans from response content.
HelloDto dto = client.request()
.path("hello").queryParam("name", "Rob").queryParam("say", "Whats up")
.GET()
.bean(HelloDto.class);
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbody
(byte[] body) Set the body content as a bytes.body
(BodyContent bodyContent) Set encoded body content.body
(InputStream stream) Set the body content with supplied InputStream.Set the body as a bean using the default content type.Set the body as a bean additionally specifying the type that will be used to serialise the content (e.g.Set the body as a bean with the given content type and additionally specifying the type that will be used to serialise the content (e.g.Set the body as a bean additionally specifying the type that will be used to serialise the content (e.g.Set the body as a bean with the given content type using a BodyWriter.Set the body content as a string using the default content type.Set the body content using http BodyPublisher.Set the body content with supplied InputStream.body
(Supplier<? extends InputStream> supplier) Set the body content with supplied InputStream.Get the body content for this request if available.DELETE()
Execute the request as a DELETE.errorMapper
(Function<HttpException, RuntimeException> errorMapper) Set the mapper used to transformHttpException
into a different kind of exception.Add a form parameter.Add a form parameter.Add the form parameters via a map.GET()
Execute the request as a GET.<E> E
getAttribute
(String key) Return a custom attribute typically set by aRequestIntercept.beforeRequest(HttpClientRequest)
.gzip
(boolean gzip) Set if body content should be gzip encoded.HEAD()
Execute the request as a HEAD.Return the header values that have been set for the given header name.Add the header to the request implicitly converting the value to a String.Add the header to the request.header
(String name, Collection<String> value) Add the headers to the request via Collection.Add the headers to the request via map.headerAddIfAbsent
(String name, Object value) Add the header to the request but only if there is no existing value for the given header.headers()
Return the header values that have been set for this request.label()
Return the label that has been set on this request.Set a label for the request.matrixParam
(String name, Object value) Add a matrix parameter to the current path segment.matrixParam
(String name, String value) Add a matrix parameter to the current path segment.method()
The Http Verb (GET, POST, PUT etc) of this request.PATCH()
Execute the request as a PATCH.path
(int val) Add a path segment to the URL.path
(long val) Add a path segment to the URL.Add a path segment to the URL.Add a path segment to the URL.POST()
Execute the request as a POST.PUT()
Execute the request as a PUT.queryParam
(String name, Object value) Add a query parameter, if value is a collection then it's values are appended with the same keyqueryParam
(String name, String value) Add a query parameterdefault HttpClientRequest
queryParam
(String name, Collection<String> values) Add a query parameter with multiple valuesqueryParam
(Map<String, ?> params) Add a multiple query parameters as name value map.requestTimeout
(Duration requestTimeout) Set the request timeout to use for this request.long
After the response is returned this method returns the response time in microseconds.setAttribute
(String key, Object value) Used to pass custom attribute betweenRequestIntercept
methods.For this request skip using an Authorization token.For this request suppress payload logging.TRACE()
Execute the request as a TRACE.url()
The URL for this request including the query parameters.Set the URL to use replacing the base URL.
-
Method Details
-
skipAuthToken
HttpClientRequest skipAuthToken()For this request skip using an Authorization token.This is automatically set on the request passed to
AuthTokenProvider.obtainToken(HttpClientRequest)
. -
suppressLogging
HttpClientRequest suppressLogging()For this request suppress payload logging.The payload contains sensitive content and the request and response content should be suppressed and not included in request logging.
-
label
Set a label for the request. The label is intended to be used to group and identify metrics for the request.- Parameters:
label
- The label that can be used to identify metrics for the request
-
label
String label()Return the label that has been set on this request.Typically the label would be read in
RequestIntercept.afterResponse(HttpResponse, HttpClientRequest)
to assign request execution metrics. -
setAttribute
Used to pass custom attribute betweenRequestIntercept
methods.Allows us to pass something between
beforeRequest
andafterResponse
methods of aRequestIntercept
or between multipleRequestIntercept
.- Parameters:
key
- The unique key used to store the attributevalue
- The attribute to store
-
getAttribute
Return a custom attribute typically set by aRequestIntercept.beforeRequest(HttpClientRequest)
.- Type Parameters:
E
- The inferred type of the attribute- Parameters:
key
- The key for the custom attribute- Returns:
- The custom attribute
-
requestTimeout
Set the request timeout to use for this request. When not set the default request timeout will be used.- Parameters:
requestTimeout
- The request timeout to use for this request.- Returns:
- The request being built
-
headerAddIfAbsent
Add the header to the request but only if there is no existing value for the given header.- Parameters:
name
- The header namevalue
- The header value- Returns:
- The request being built
-
header
Add the header to the request.- Parameters:
name
- The header namevalue
- The header value- Returns:
- The request being built
-
header
Add the header to the request implicitly converting the value to a String. If the value is a collection then it's values are appended with the same key- Parameters:
name
- The header namevalue
- The header value- Returns:
- The request being built
-
header
Add the headers to the request via map.- Parameters:
headers
- The headers as name value map to add- Returns:
- The request being built
-
header
Add the headers to the request via Collection.- Parameters:
name
- The header namevalue
- The header values- Returns:
- The request being built
-
header
Return the header values that have been set for the given header name.- Returns:
- The headers values or an empty collection if the header has not been specified yet.
-
headers
Return the header values that have been set for this request.- Returns:
- The headers values or an empty map if no headers have been specified yet.
-
gzip
Set if body content should be gzip encoded.- Parameters:
gzip
- Set true to gzip encode the body content.- Returns:
- The request being built
-
url
Set the URL to use replacing the base URL.{code HttpResponse
res = client.request() .url("http://127.0.0.1:8889") .path("hello") .GET() .asString(); } - Parameters:
url
- The url effectively replacing the base url.- Returns:
- The request being built
- See Also:
-
method
String method()The Http Verb (GET, POST, PUT etc) of this request.- Returns:
- The Http Verb of this request.
-
url
String url()The URL for this request including the query parameters.- Returns:
- The url for this request
-
path
Add a path segment to the URL.- Parameters:
path
- The path segment to add to the URL path.- Returns:
- The request being built
-
path
Add a path segment to the URL.- Parameters:
val
- The value to add to the URL path.- Returns:
- The request being built
-
path
Add a path segment to the URL.- Parameters:
val
- The value to add to the URL path.- Returns:
- The request being built
-
path
Add a path segment to the URL.- Parameters:
val
- The value to add to the URL path.- Returns:
- The request being built
-
matrixParam
Add a matrix parameter to the current path segment.- Parameters:
name
- The matrix parameter namevalue
- The matrix parameter value which can be null- Returns:
- The request being built
-
matrixParam
Add a matrix parameter to the current path segment.- Parameters:
name
- The matrix parameter namevalue
- The matrix parameter value which can be null- Returns:
- The request being built
-
queryParam
Add a query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter which can be null- Returns:
- The request being built
-
queryParam
Add a query parameter, if value is a collection then it's values are appended with the same key- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter which can be null- Returns:
- The request being built
-
queryParam
Add a multiple query parameters as name value map.- Parameters:
params
- The query parameters- Returns:
- The request being built
-
queryParam
Add a query parameter with multiple values- Parameters:
name
- The name of the query parametervalues
- The values of the query parameter which can be null- Returns:
- The request being built
-
formParam
Add a form parameter.- Parameters:
name
- The form parameter namevalue
- The form parameter value which can be null- Returns:
- The request being built
-
formParam
Add a form parameter.- Parameters:
name
- The form parameter namevalue
- The form parameter value which can be null- Returns:
- The request being built
-
formParam
Add the form parameters via a map.- Parameters:
params
- The form parameters as name value map- Returns:
- The request being built
-
body
Set encoded body content. -
body
Set the body as a bean with the given content type using a BodyWriter. -
body
Set the body as a bean using the default content type.The default content type will often be
application/json; charset=utf8
. -
body
Set the body as a bean additionally specifying the type that will be used to serialise the content (e.g. JsonbAdapter).Specifying the type allows the bean instance to be a type that extends a type that is known to JsonbAdapter / the body content adapter used.
- Parameters:
bean
- The body content as an instancetype
- The type used by the body content adapter to write the body content- Returns:
- The request being built
-
body
Set the body as a bean additionally specifying the type that will be used to serialise the content (e.g. JsonbAdapter).Specifying the type allows the bean instance to be a type that extends a type that is known to JsonbAdapter / the body content adapter used.
- Parameters:
bean
- The body content as an instancetype
- The type used by the body content adapter to write the body content- Returns:
- The request being built
-
body
Set the body as a bean with the given content type and additionally specifying the type that will be used to serialise the content (e.g. JsonbAdapter).Specifying the type allows the bean instance to be a type that extends a type that is known to JsonbAdapter / the body content adapter used.
- Parameters:
bean
- The body content as an instancetype
- The type used by the body content adapter to write the body contentcontentType
- The content type of the body- Returns:
- The request being built
-
body
Set the body content as a string using the default content type.- Parameters:
body
- The body content- Returns:
- The request being built
-
body
Set the body content as a bytes.- Parameters:
body
- The body content- Returns:
- The request being built
-
body
Set the body content with supplied InputStream.- Parameters:
supplier
- The supplier of InputStream content to send as body content- Returns:
- The request being built
-
body
Set the body content with supplied InputStream.- Parameters:
stream
- The InputStream content to send as body content- Returns:
- The request being built
-
body
Set the body content with supplied InputStream.- Parameters:
file
- The file to send as body content- Returns:
- The request being built
-
body
Set the body content using http BodyPublisher.- Parameters:
body
- The body content- Returns:
- The request being built
-
bodyContent
Optional<BodyContent> bodyContent()Get the body content for this request if available. Will return an empty optional for streaming calls- Returns:
- The request body
-
errorMapper
Set the mapper used to transformHttpException
into a different kind of exception.When set, all
HttpException
that are thrown by this request will be caught and transformed into more specific exception with the given function by default.- Parameters:
errorMapper
- function to map the httpException- Returns:
- The request being built
-
GET
HttpClientResponse GET()Execute the request as a GET. -
POST
HttpClientResponse POST()Execute the request as a POST. -
PUT
HttpClientResponse PUT()Execute the request as a PUT. -
PATCH
HttpClientResponse PATCH()Execute the request as a PATCH. -
DELETE
HttpClientResponse DELETE()Execute the request as a DELETE. -
TRACE
HttpClientResponse TRACE()Execute the request as a TRACE. -
HEAD
HttpClientResponse HEAD()Execute the request as a HEAD. -
responseTimeMicros
long responseTimeMicros()After the response is returned this method returns the response time in microseconds.This is useful for use in
RequestIntercept.afterResponse(HttpResponse, HttpClientRequest)
-