public interface HttpRequest<R extends HttpRequest>
Modifier and Type | Method and Description |
---|---|
R |
accept(String value)
The Accept heder to send (e.g.
|
HttpResponse |
asEmpty()
Executes the request and returns the response without parsing the body
|
CompletableFuture<HttpResponse<Empty>> |
asEmptyAsync()
Executes the request asynchronously and returns the response without parsing the body
|
CompletableFuture<HttpResponse<Empty>> |
asEmptyAsync(Callback<Empty> callback)
Executes the request asynchronously and returns a empty response which is passed to a callback
|
HttpResponse<File> |
asFile(String path)
Executes the request and writes the contents into a file
|
CompletableFuture<HttpResponse<File>> |
asFileAsync(String path)
asynchronously executes the request and writes the contents into a file
|
CompletableFuture<HttpResponse<File>> |
asFileAsync(String path,
Callback<File> callback)
asynchronously executes the request and writes the contents into a file
|
HttpResponse<JsonNode> |
asJson()
Executes the request and returns the response with the body mapped into a JsonNode
|
CompletableFuture<HttpResponse<JsonNode>> |
asJsonAsync()
Executes the request asynchronously and returns the response with the body mapped into a JsonNode
|
CompletableFuture<HttpResponse<JsonNode>> |
asJsonAsync(Callback<JsonNode> callback)
Executes the request asynchronously and returns the response with the body mapped into a JsonNode
|
<T> HttpResponse<T> |
asObject(Class<? extends T> responseClass)
Executes the request and returns the response with the body mapped into T by a configured ObjectMapper
|
<T> HttpResponse<T> |
asObject(java.util.function.Function<RawResponse,T> function)
Execute the request and pass the raw response to a function for mapping.
|
<T> HttpResponse<T> |
asObject(GenericType<T> genericType)
Executes the request and returns the response with the body mapped into T by a configured ObjectMapper
|
<T> CompletableFuture<HttpResponse<T>> |
asObjectAsync(Class<? extends T> responseClass)
Executes the request asynchronously and returns response with the body mapped into T by a configured ObjectMapper
|
<T> CompletableFuture<HttpResponse<T>> |
asObjectAsync(Class<? extends T> responseClass,
Callback<T> callback)
Executes the request asynchronously, mapping to a type via the configured object mapper and then passed to a callback handler.
|
<T> CompletableFuture<HttpResponse<T>> |
asObjectAsync(java.util.function.Function<RawResponse,T> function)
Executes the request asynchronously, and pass the raw response to a function for mapping.
|
<T> CompletableFuture<HttpResponse<T>> |
asObjectAsync(GenericType<T> genericType)
Executes the request asynchronously, and use a GenericType with the ObjectMapper
|
<T> CompletableFuture<HttpResponse<T>> |
asObjectAsync(GenericType<T> genericType,
Callback<T> callback)
Executes the request asynchronously, and use a GenericType with the ObjectMapper
|
<T> PagedList<T> |
asPaged(java.util.function.Function<HttpRequest,HttpResponse> mappingFunction,
java.util.function.Function<HttpResponse<T>,String> linkExtractor)
Allows for following paging links common in many APIs.
|
HttpResponse<String> |
asString()
Executes the request and returns the response with the body mapped into a String
|
CompletableFuture<HttpResponse<String>> |
asStringAsync()
Executes the request asynchronously and returns the response with the body mapped into a String
|
CompletableFuture<HttpResponse<String>> |
asStringAsync(Callback<String> callback)
Executes the request asynchronously and returns the response with the body mapped into a String
|
R |
basicAuth(String username,
String password)
Basic auth credentials
|
R |
connectTimeout(int millies)
Set a connect timeout for this request
|
default Optional<Body> |
getBody() |
int |
getConnectTimeout() |
Headers |
getHeaders() |
HttpMethod |
getHttpMethod() |
Proxy |
getProxy() |
int |
getSocketTimeout() |
String |
getUrl() |
R |
header(String name,
String value)
Add a http header, HTTP supports multiple of the same header.
|
R |
headerReplace(String name,
String value)
Replace a header value or add it if it doesn't exist
|
R |
headers(Map<String,String> headerMap)
Add headers as a map
|
R |
proxy(String host,
int port)
Set a proxy for this request.
|
R |
queryString(Map<String,Object> parameters)
Add query params as a map of name value pairs
|
R |
queryString(String name,
Collection<?> value)
Add multiple param with the same param name.
|
R |
queryString(String name,
Object value)
add a query param to the url.
|
R |
responseEncoding(String encoding)
The encoding to expect the response to be for cases where the server fails to respond with the proper encoding
|
R |
routeParam(Map<String,Object> params)
add a route param map that replaces the matching {name}
For example routeParam(Map.of("name", "fred")) will replace {name} in
https://localhost/users/{user}
to
https://localhost/users/fred
|
R |
routeParam(String name,
String value)
add a route param that replaces the matching {name}
For example routeParam("name", "fred") will replace {name} in
https://localhost/users/{user}
to
https://localhost/users/fred
|
R |
socketTimeout(int millies)
Set a socket timeout for this request
|
void |
thenConsume(java.util.function.Consumer<RawResponse> consumer)
Execute the request and pass the raw response to a consumer.
|
void |
thenConsumeAsync(java.util.function.Consumer<RawResponse> consumer)
Execute the request asynchronously and pass the raw response to a consumer.
|
HttpRequestSummary |
toSummary() |
R |
withObjectMapper(ObjectMapper mapper)
Pass a ObjectMapper for the request.
|
R routeParam(String name, String value)
name
- the name of the param (do not include curly braces {}value
- the value to replace the placeholder withR routeParam(Map<String,Object> params)
params
- a map of path paramsR basicAuth(String username, String password)
username
- the usernamepassword
- the passwordR accept(String value)
value
- a valid mime type for the Accept headerR responseEncoding(String encoding)
encoding
- a valid mime type for the Accept headerR header(String name, String value)
name
- name of the headervalue
- value for the headerR headerReplace(String name, String value)
name
- name of the headervalue
- value for the headerR headers(Map<String,String> headerMap)
headerMap
- a map of headersR queryString(String name, Object value)
name
- the name of the paramvalue
- the value of the paramR queryString(String name, Collection<?> value)
name
- the name of the paramvalue
- a collection of valuesR queryString(Map<String,Object> parameters)
parameters
- a map of paramsR withObjectMapper(ObjectMapper mapper)
mapper
- the ObjectMapperR socketTimeout(int millies)
millies
- the time in milliesR connectTimeout(int millies)
millies
- the time in milliesR proxy(String host, int port)
host
- the host urlport
- the proxy portHttpResponse<String> asString()
CompletableFuture<HttpResponse<String>> asStringAsync()
CompletableFuture<HttpResponse<String>> asStringAsync(Callback<String> callback)
callback
- a callback handlerHttpResponse<JsonNode> asJson()
CompletableFuture<HttpResponse<JsonNode>> asJsonAsync()
CompletableFuture<HttpResponse<JsonNode>> asJsonAsync(Callback<JsonNode> callback)
callback
- a callback handler<T> HttpResponse<T> asObject(Class<? extends T> responseClass)
T
- the return typeresponseClass
- the class to return. This will be passed to the ObjectMapper<T> HttpResponse<T> asObject(GenericType<T> genericType)
T
- the return typegenericType
- the genertic type to return. This will be passed to the ObjectMapper<T> HttpResponse<T> asObject(java.util.function.Function<RawResponse,T> function)
T
- The type of the response mappingfunction
- the function to map the response into a object of T<T> CompletableFuture<HttpResponse<T>> asObjectAsync(Class<? extends T> responseClass)
T
- the return typeresponseClass
- the class type to map to<T> CompletableFuture<HttpResponse<T>> asObjectAsync(Class<? extends T> responseClass, Callback<T> callback)
T
- the return typeresponseClass
- the type for the ObjectMapper to map tocallback
- a callback for handling the body post mapping<T> CompletableFuture<HttpResponse<T>> asObjectAsync(GenericType<T> genericType)
T
- the type of the responsegenericType
- the generic type containing the type<T> CompletableFuture<HttpResponse<T>> asObjectAsync(GenericType<T> genericType, Callback<T> callback)
T
- the type of the responsegenericType
- the generic type containing the typecallback
- a callback for handling the body post mapping<T> CompletableFuture<HttpResponse<T>> asObjectAsync(java.util.function.Function<RawResponse,T> function)
T
- the type of the responsefunction
- a function to map the raw request into a objectHttpResponse<File> asFile(String path)
path
- The path to the file.CompletableFuture<HttpResponse<File>> asFileAsync(String path)
path
- The path to the file.CompletableFuture<HttpResponse<File>> asFileAsync(String path, Callback<File> callback)
path
- The path to the file.callback
- a callback for handling the body post mapping<T> PagedList<T> asPaged(java.util.function.Function<HttpRequest,HttpResponse> mappingFunction, java.util.function.Function<HttpResponse<T>,String> linkExtractor)
T
- the type of response.mappingFunction
- a function to return the desired return type leveraging one of the as* methods (asString, asObject, etc).linkExtractor
- a function to extract a "next" link to follow. Retuning a null or empty string ends the pagingHttpResponse asEmpty()
CompletableFuture<HttpResponse<Empty>> asEmptyAsync()
CompletableFuture<HttpResponse<Empty>> asEmptyAsync(Callback<Empty> callback)
callback
- the callback* Executes the request asynchronously and returns the response without parsing the bodyvoid thenConsume(java.util.function.Consumer<RawResponse> consumer)
consumer
- a consumer functionvoid thenConsumeAsync(java.util.function.Consumer<RawResponse> consumer)
consumer
- a consumer functionHttpMethod getHttpMethod()
String getUrl()
Headers getHeaders()
int getSocketTimeout()
int getConnectTimeout()
Proxy getProxy()
HttpRequestSummary toSummary()
Copyright © 2019. All rights reserved.