public interface HttpClientRequest
Http request that is built and sent to the server.
Largely wraps the standard JDK HttpRequest with additional support for converting beans to body content and converting beans from response content.
HelloDto dto = clientContext.request()
.path("hello").queryParam("name", "Rob").queryParam("say", "Ki ora")
.get().bean(HelloDto.class);
- See Also:
HttpClientContext
-
Method Summary
Modifier and TypeMethodDescriptionbody(byte[] body)
Set the body content as a bytes.body(BodyContent bodyContent)
Set encoded body content.Set the body as a bean using the default content type.Set the body as a bean with the given content type using a BodyWriter.Set the body content as a string.body(HttpRequest.BodyPublisher body)
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.delete()
Execute the request as a DELETE.Add a Long value form parameter.Add a form parameter.Add a Long value form parameter.get()
Execute the request as a GET.gzip(boolean gzip)
Set if body content should be gzip encoded.Add the header to the request.matrixParam(String name, String value)
Add a matrix parameter to the current path segment.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.Add a path segment to the URL.post()
Execute the request as a POST.put()
Execute the request as a PUT.queryParam(String name, Boolean value)
Add a Boolean query parameterqueryParam(String name, Integer value)
Add a Integer query parameterqueryParam(String name, Long value)
Add a Long query parameterqueryParam(String name, String value)
Add a query parameterqueryParam(String name, Instant value)
Add a Instant query parameter as ISO-8601 format.queryParam(String name, LocalDate value)
Add a LocalDate query parameterqueryParam(String name, LocalDateTime value)
Add a LocalDateTime query parameterqueryParam(String name, LocalTime value)
Add a LocalTime query parameterqueryParam(String name, UUID value)
Add a UUID query parameterrequestTimeout(Duration requestTimeout)
Set the request timeout to use for this request.For this request skip using an Authorization token.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)
. -
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
-
header
Add the header to the request.- Parameters:
name
- The header namevalue
- The header value- Returns:
- The request being built
-
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 = clientContext.request() .url("http://127.0.0.1:8887") .path("hello") .get().asString(); } - Parameters:
url
- The url effectively replacing the base url.- Returns:
- The request being built
- See Also:
HttpClientContext.Builder.withBaseUrl(String)
-
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
-
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- Returns:
- The request being built
-
queryParam
Add a query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a Integer query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a Long query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a UUID query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a Boolean query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a LocalDate query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a LocalTime query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a LocalDateTime query parameter- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
queryParam
Add a Instant query parameter as ISO-8601 format.- Parameters:
name
- The name of the query parametervalue
- The value of the query parameter- Returns:
- The request being built
-
formParam
Add a form parameter.- Parameters:
name
- The form parameter namevalue
- The form parameter value- Returns:
- The request being built
-
formParam
Add a Long value form parameter. -
formParam
Add a Long value form parameter. -
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 beapplication/json; charset=utf8
. -
body
Set the body content as a string.- 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:
file
- The file to send as body content- Returns:
- The request being built
- Throws:
FileNotFoundException
-
body
Set the body content using http BodyPublisher.- Parameters:
body
- The body content- 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. -
delete
HttpClientResponse delete()Execute the request as a DELETE.
-