Package kong.unirest.core
Class BaseRequest<R extends HttpRequest>
- java.lang.Object
-
- kong.unirest.core.BaseRequest<R>
-
- All Implemented Interfaces:
HttpRequest<R>
- Direct Known Subclasses:
HttpRequestBody,HttpRequestJsonPatch,HttpRequestMultiPart,HttpRequestNoBody,HttpRequestUniBody
abstract class BaseRequest<R extends HttpRequest> extends java.lang.Object implements HttpRequest<R>
-
-
Field Summary
Fields Modifier and Type Field Description private intcallCountprotected Configconfigprivate java.lang.IntegerconnectTimeoutprivate java.time.Instantcreationprivate ProgressMonitordownloadMonitorprotected Headersheadersprotected HttpMethodmethodprivate java.util.Optional<ObjectMapper>objectMapperprivate java.lang.StringresponseEncodingprotected Pathurlprivate java.net.http.HttpClient.Versionversion
-
Constructor Summary
Constructors Constructor Description BaseRequest(BaseRequest httpRequest)BaseRequest(Config config, HttpMethod method, java.lang.String url)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Raccept(java.lang.String value)The Accept header to send (e.g.HttpResponse<byte[]>asBytes()Executes the request and returns the response with the body mapped into a byte[]java.util.concurrent.CompletableFuture<HttpResponse<byte[]>>asBytesAsync()Executes the request asynchronously and returns the response with the body mapped into a byte[]java.util.concurrent.CompletableFuture<HttpResponse<byte[]>>asBytesAsync(Callback<byte[]> callback)Executes the request asynchronously and returns the response with the body mapped into a byte[]HttpResponse<Empty>asEmpty()Executes the request and returns the response without parsing the bodyjava.util.concurrent.CompletableFuture<HttpResponse<Empty>>asEmptyAsync()Executes the request asynchronously and returns the response without parsing the bodyjava.util.concurrent.CompletableFuture<HttpResponse<Empty>>asEmptyAsync(Callback<Empty> callback)Executes the request asynchronously and returns a empty response which is passed to a callbackHttpResponse<java.io.File>asFile(java.lang.String path, java.nio.file.CopyOption... copyOptions)Executes the request and writes the contents into a filejava.util.concurrent.CompletableFuture<HttpResponse<java.io.File>>asFileAsync(java.lang.String path, java.nio.file.CopyOption... copyOptions)asynchronously executes the request and writes the contents into a filejava.util.concurrent.CompletableFuture<HttpResponse<java.io.File>>asFileAsync(java.lang.String path, Callback<java.io.File> callback, java.nio.file.CopyOption... copyOptions)asynchronously executes the request and writes the contents into a fileHttpResponse<JsonNode>asJson()Executes the request and returns the response with the body mapped into a JsonNodejava.util.concurrent.CompletableFuture<HttpResponse<JsonNode>>asJsonAsync()Executes the request asynchronously and returns the response with the body mapped into a JsonNodejava.util.concurrent.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(java.lang.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> java.util.concurrent.CompletableFuture<HttpResponse<T>>asObjectAsync(java.lang.Class<? extends T> responseClass)Executes the request asynchronously and returns response with the body mapped into T by a configured ObjectMapper<T> java.util.concurrent.CompletableFuture<HttpResponse<T>>asObjectAsync(java.lang.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> java.util.concurrent.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> java.util.concurrent.CompletableFuture<HttpResponse<T>>asObjectAsync(GenericType<T> genericType)Executes the request asynchronously, and use a GenericType with the ObjectMapper<T> java.util.concurrent.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>,java.lang.String> linkExtractor)Allows for following paging links common in many APIs.HttpResponse<java.lang.String>asString()Executes the request and returns the response with the body mapped into a Stringjava.util.concurrent.CompletableFuture<HttpResponse<java.lang.String>>asStringAsync()Executes the request asynchronously and returns the response with the body mapped into a Stringjava.util.concurrent.CompletableFuture<HttpResponse<java.lang.String>>asStringAsync(Callback<java.lang.String> callback)Executes the request asynchronously and returns the response with the body mapped into a StringRbasicAuth(java.lang.String username, java.lang.String password)Basic auth credentialsRcookie(java.lang.String name, java.lang.String value)Add a simple cookie headerRcookie(java.util.Collection<Cookie> cookies)Add a collection of cookie headersRcookie(Cookie cookie)Add a simple cookie headerRdownloadMonitor(ProgressMonitor monitor)sets a download monitor for monitoring the response.booleanequals(java.lang.Object o)private <T> java.util.function.Function<RawResponse,HttpResponse<T>>funcResponse(java.util.function.Function<RawResponse,T> function)private java.util.function.Function<RawResponse,HttpResponse<java.lang.Object>>getConsumer(java.util.function.Consumer<RawResponse> consumer)java.time.InstantgetCreationTime()ProgressMonitorgetDownloadMonitor()HeadersgetHeaders()HttpMethodgetHttpMethod()protected ObjectMappergetObjectMapper()(package private) PathgetPath()java.lang.IntegergetRequestTimeout()java.lang.StringgetUrl()java.net.http.HttpClient.VersiongetVersion()gets the version for the request, or null if not set.inthashCode()Rheader(java.lang.String name, java.lang.String value)Add a http header, HTTP supports multiple of the same header.RheaderReplace(java.lang.String name, java.lang.String value)Replace a header value or add it if it doesn't existRheaders(java.util.Map<java.lang.String,java.lang.String> headerMap)Add headers as a mapRheadersReplace(java.util.Map<java.lang.String,java.lang.String> headerMap)Replace headers as a mapRqueryString(java.lang.String name, java.lang.Object value)add a query param to the url.RqueryString(java.lang.String name, java.util.Collection<?> value)Add multiple param with the same param name.RqueryString(java.util.Map<java.lang.String,java.lang.Object> parameters)Add query params as a map of name value pairsprivate <E> HttpResponse<E>request(java.util.function.Function<RawResponse,HttpResponse<E>> transformer, java.lang.Class<?> resultType)private <T> java.util.concurrent.CompletableFuture<HttpResponse<T>>requestAsync(HttpRequest request, java.util.function.Function<RawResponse,HttpResponse<T>> transformer, java.util.concurrent.CompletableFuture<HttpResponse<T>> callback, java.lang.Class<?> resultType)RrequestTimeout(int millies)Set a timeout for this requestRresponseEncoding(java.lang.String encoding)The encoding to expect the response to be for cases where the server fails to respond with the proper encodingRrouteParam(java.lang.String name, java.lang.String value)add a route param that replaces the matching {name} For example routeParam("name", "fred") will replace {name} in https://localhost/users/{name} to https://localhost/users/fredRrouteParam(java.util.Map<java.lang.String,java.lang.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/{name} to https://localhost/users/fredvoidthenConsume(java.util.function.Consumer<RawResponse> consumer)Execute the request and pass the raw response to a consumer.voidthenConsumeAsync(java.util.function.Consumer<RawResponse> consumer)Execute the request asynchronously and pass the raw response to a consumer.HttpRequestSummarytoSummary()private <T> TvalueOr(T x, java.util.function.Supplier<T> o)Rversion(java.net.http.HttpClient.Version value)sets the HTTP version for the request.RwithObjectMapper(ObjectMapper mapper)Pass a ObjectMapper for the request.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface kong.unirest.core.HttpRequest
accept, getBody
-
-
-
-
Field Detail
-
creation
private java.time.Instant creation
-
callCount
private int callCount
-
objectMapper
private java.util.Optional<ObjectMapper> objectMapper
-
responseEncoding
private java.lang.String responseEncoding
-
headers
protected Headers headers
-
config
protected final Config config
-
method
protected HttpMethod method
-
url
protected Path url
-
connectTimeout
private java.lang.Integer connectTimeout
-
downloadMonitor
private ProgressMonitor downloadMonitor
-
version
private java.net.http.HttpClient.Version version
-
-
Constructor Detail
-
BaseRequest
BaseRequest(BaseRequest httpRequest)
-
BaseRequest
BaseRequest(Config config, HttpMethod method, java.lang.String url)
-
-
Method Detail
-
routeParam
public R routeParam(java.lang.String name, java.lang.String value)
Description copied from interface:HttpRequestadd a route param that replaces the matching {name} For example routeParam("name", "fred") will replace {name} in https://localhost/users/{name} to https://localhost/users/fred- Specified by:
routeParamin interfaceHttpRequest<R extends HttpRequest>- Parameters:
name- the name of the param (do not include curly braces {}value- the value to replace the placeholder with- Returns:
- this request builder
-
routeParam
public R routeParam(java.util.Map<java.lang.String,java.lang.Object> params)
Description copied from interface:HttpRequestadd a route param map that replaces the matching {name} For example routeParam(Map.of("name", "fred")) will replace {name} in https://localhost/users/{name} to https://localhost/users/fred- Specified by:
routeParamin interfaceHttpRequest<R extends HttpRequest>- Parameters:
params- a map of path params- Returns:
- this request builder
-
basicAuth
public R basicAuth(java.lang.String username, java.lang.String password)
Description copied from interface:HttpRequestBasic auth credentials- Specified by:
basicAuthin interfaceHttpRequest<R extends HttpRequest>- Parameters:
username- the usernamepassword- the password- Returns:
- this request builder
-
accept
public R accept(java.lang.String value)
Description copied from interface:HttpRequestThe Accept header to send (e.g. application/json)- Specified by:
acceptin interfaceHttpRequest<R extends HttpRequest>- Parameters:
value- a valid mime type for the Accept header- Returns:
- this request builder
-
header
public R header(java.lang.String name, java.lang.String value)
Description copied from interface:HttpRequestAdd a http header, HTTP supports multiple of the same header. This will continue to append new values- Specified by:
headerin interfaceHttpRequest<R extends HttpRequest>- Parameters:
name- name of the headervalue- value for the header- Returns:
- this request builder
-
headerReplace
public R headerReplace(java.lang.String name, java.lang.String value)
Description copied from interface:HttpRequestReplace a header value or add it if it doesn't exist- Specified by:
headerReplacein interfaceHttpRequest<R extends HttpRequest>- Parameters:
name- name of the headervalue- value for the header- Returns:
- this request builder
-
headers
public R headers(java.util.Map<java.lang.String,java.lang.String> headerMap)
Description copied from interface:HttpRequestAdd headers as a map- Specified by:
headersin interfaceHttpRequest<R extends HttpRequest>- Parameters:
headerMap- a map of headers- Returns:
- this request builder
-
headersReplace
public R headersReplace(java.util.Map<java.lang.String,java.lang.String> headerMap)
Description copied from interface:HttpRequestReplace headers as a map- Specified by:
headersReplacein interfaceHttpRequest<R extends HttpRequest>- Parameters:
headerMap- a map of headers- Returns:
- this request builder
-
responseEncoding
public R responseEncoding(java.lang.String encoding)
Description copied from interface:HttpRequestThe encoding to expect the response to be for cases where the server fails to respond with the proper encoding- Specified by:
responseEncodingin interfaceHttpRequest<R extends HttpRequest>- Parameters:
encoding- a valid mime type for the Accept header- Returns:
- this request builder
-
cookie
public R cookie(java.lang.String name, java.lang.String value)
Description copied from interface:HttpRequestAdd a simple cookie header- Specified by:
cookiein interfaceHttpRequest<R extends HttpRequest>- Parameters:
name- the name of the cookievalue- the value of the cookie- Returns:
- this request builder
-
cookie
public R cookie(Cookie cookie)
Description copied from interface:HttpRequestAdd a simple cookie header- Specified by:
cookiein interfaceHttpRequest<R extends HttpRequest>- Parameters:
cookie- a cookie- Returns:
- this request builder
-
cookie
public R cookie(java.util.Collection<Cookie> cookies)
Description copied from interface:HttpRequestAdd a collection of cookie headers- Specified by:
cookiein interfaceHttpRequest<R extends HttpRequest>- Parameters:
cookies- a cookie- Returns:
- this request builder
-
queryString
public R queryString(java.lang.String name, java.util.Collection<?> value)
Description copied from interface:HttpRequestAdd multiple param with the same param name. queryString("name", Arrays.asList("bob", "linda")) will result in ?name=bob&name=linda- Specified by:
queryStringin interfaceHttpRequest<R extends HttpRequest>- Parameters:
name- the name of the paramvalue- a collection of values- Returns:
- this request builder
-
queryString
public R queryString(java.lang.String name, java.lang.Object value)
Description copied from interface:HttpRequestadd a query param to the url. The value will be URL-Encoded- Specified by:
queryStringin interfaceHttpRequest<R extends HttpRequest>- Parameters:
name- the name of the paramvalue- the value of the param- Returns:
- this request builder
-
queryString
public R queryString(java.util.Map<java.lang.String,java.lang.Object> parameters)
Description copied from interface:HttpRequestAdd query params as a map of name value pairs- Specified by:
queryStringin interfaceHttpRequest<R extends HttpRequest>- Parameters:
parameters- a map of params- Returns:
- this request builder
-
requestTimeout
public R requestTimeout(int millies)
Description copied from interface:HttpRequestSet a timeout for this request- Specified by:
requestTimeoutin interfaceHttpRequest<R extends HttpRequest>- Parameters:
millies- the time in millies- Returns:
- this request builder
-
withObjectMapper
public R withObjectMapper(ObjectMapper mapper)
Description copied from interface:HttpRequestPass a ObjectMapper for the request. This will override any globally configured ObjectMapper- Specified by:
withObjectMapperin interfaceHttpRequest<R extends HttpRequest>- Parameters:
mapper- the ObjectMapper- Returns:
- this request builder
-
downloadMonitor
public R downloadMonitor(ProgressMonitor monitor)
Description copied from interface:HttpRequestsets a download monitor for monitoring the response. this could be used for drawing a progress bar- Specified by:
downloadMonitorin interfaceHttpRequest<R extends HttpRequest>- Parameters:
monitor- a ProgressMonitor- Returns:
- this request builder
-
getDownloadMonitor
public ProgressMonitor getDownloadMonitor()
-
version
public R version(java.net.http.HttpClient.Version value)
Description copied from interface:HttpRequestsets the HTTP version for the request. This will override any global config- Specified by:
versionin interfaceHttpRequest<R extends HttpRequest>- Parameters:
value- the version- Returns:
- this request builder
-
asEmpty
public HttpResponse<Empty> asEmpty()
Description copied from interface:HttpRequestExecutes the request and returns the response without parsing the body- Specified by:
asEmptyin interfaceHttpRequest<R extends HttpRequest>- Returns:
- the basic HttpResponse
-
asEmptyAsync
public java.util.concurrent.CompletableFuture<HttpResponse<Empty>> asEmptyAsync()
Description copied from interface:HttpRequestExecutes the request asynchronously and returns the response without parsing the body- Specified by:
asEmptyAsyncin interfaceHttpRequest<R extends HttpRequest>- Returns:
- a CompletableFuture of a HttpResponse
-
asEmptyAsync
public java.util.concurrent.CompletableFuture<HttpResponse<Empty>> asEmptyAsync(Callback<Empty> callback)
Description copied from interface:HttpRequestExecutes the request asynchronously and returns a empty response which is passed to a callback- Specified by:
asEmptyAsyncin interfaceHttpRequest<R extends HttpRequest>- Parameters:
callback- the callback* Executes the request asynchronously and returns the response without parsing the body- Returns:
- a CompletableFuture of a HttpResponse
-
asString
public HttpResponse<java.lang.String> asString() throws UnirestException
Description copied from interface:HttpRequestExecutes the request and returns the response with the body mapped into a String- Specified by:
asStringin interfaceHttpRequest<R extends HttpRequest>- Returns:
- response
- Throws:
UnirestException
-
asStringAsync
public java.util.concurrent.CompletableFuture<HttpResponse<java.lang.String>> asStringAsync()
Description copied from interface:HttpRequestExecutes the request asynchronously and returns the response with the body mapped into a String- Specified by:
asStringAsyncin interfaceHttpRequest<R extends HttpRequest>- Returns:
- a CompletableFuture of a response
-
asStringAsync
public java.util.concurrent.CompletableFuture<HttpResponse<java.lang.String>> asStringAsync(Callback<java.lang.String> callback)
Description copied from interface:HttpRequestExecutes the request asynchronously and returns the response with the body mapped into a String- Specified by:
asStringAsyncin interfaceHttpRequest<R extends HttpRequest>- Parameters:
callback- a callback handler- Returns:
- a CompletableFuture of a response
-
asBytes
public HttpResponse<byte[]> asBytes()
Description copied from interface:HttpRequestExecutes the request and returns the response with the body mapped into a byte[]- Specified by:
asBytesin interfaceHttpRequest<R extends HttpRequest>- Returns:
- response
-
asBytesAsync
public java.util.concurrent.CompletableFuture<HttpResponse<byte[]>> asBytesAsync()
Description copied from interface:HttpRequestExecutes the request asynchronously and returns the response with the body mapped into a byte[]- Specified by:
asBytesAsyncin interfaceHttpRequest<R extends HttpRequest>- Returns:
- a CompletableFuture of a response
-
asBytesAsync
public java.util.concurrent.CompletableFuture<HttpResponse<byte[]>> asBytesAsync(Callback<byte[]> callback)
Description copied from interface:HttpRequestExecutes the request asynchronously and returns the response with the body mapped into a byte[]- Specified by:
asBytesAsyncin interfaceHttpRequest<R extends HttpRequest>- Parameters:
callback- a callback handler- Returns:
- a CompletableFuture of a response
-
asJson
public HttpResponse<JsonNode> asJson() throws UnirestException
Description copied from interface:HttpRequestExecutes the request and returns the response with the body mapped into a JsonNode- Specified by:
asJsonin interfaceHttpRequest<R extends HttpRequest>- Returns:
- response
- Throws:
UnirestException
-
asJsonAsync
public java.util.concurrent.CompletableFuture<HttpResponse<JsonNode>> asJsonAsync()
Description copied from interface:HttpRequestExecutes the request asynchronously and returns the response with the body mapped into a JsonNode- Specified by:
asJsonAsyncin interfaceHttpRequest<R extends HttpRequest>- Returns:
- a CompletableFuture of a response
-
asJsonAsync
public java.util.concurrent.CompletableFuture<HttpResponse<JsonNode>> asJsonAsync(Callback<JsonNode> callback)
Description copied from interface:HttpRequestExecutes the request asynchronously and returns the response with the body mapped into a JsonNode- Specified by:
asJsonAsyncin interfaceHttpRequest<R extends HttpRequest>- Parameters:
callback- a callback handler- Returns:
- a CompletableFuture of a response
-
asObject
public <T> HttpResponse<T> asObject(java.lang.Class<? extends T> responseClass) throws UnirestException
Description copied from interface:HttpRequestExecutes the request and returns the response with the body mapped into T by a configured ObjectMapper- Specified by:
asObjectin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the return type- Parameters:
responseClass- the class to return. This will be passed to the ObjectMapper- Returns:
- a response
- Throws:
UnirestException
-
asObject
public <T> HttpResponse<T> asObject(GenericType<T> genericType) throws UnirestException
Description copied from interface:HttpRequestExecutes the request and returns the response with the body mapped into T by a configured ObjectMapper- Specified by:
asObjectin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the return type- Parameters:
genericType- the genertic type to return. This will be passed to the ObjectMapper- Returns:
- a response
- Throws:
UnirestException
-
asObject
public <T> HttpResponse<T> asObject(java.util.function.Function<RawResponse,T> function)
Description copied from interface:HttpRequestExecute the request and pass the raw response to a function for mapping. This raw response contains the original InputStream and is suitable for reading large responses.- Specified by:
asObjectin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- The type of the response mapping- Parameters:
function- the function to map the response into a object of T- Returns:
- A HttpResponse containing T as the body
-
asObjectAsync
public <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> asObjectAsync(java.util.function.Function<RawResponse,T> function)
Description copied from interface:HttpRequestExecutes the request asynchronously, and pass the raw response to a function for mapping. This raw response contains the original InputStream and is suitable for reading large responses- Specified by:
asObjectAsyncin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the type of the response- Parameters:
function- a function to map the raw request into a object- Returns:
- a CompletableFuture of a HttpResponse containing the body of T
-
asObjectAsync
public <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> asObjectAsync(java.lang.Class<? extends T> responseClass)
Description copied from interface:HttpRequestExecutes the request asynchronously and returns response with the body mapped into T by a configured ObjectMapper- Specified by:
asObjectAsyncin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the return type- Parameters:
responseClass- the class type to map to- Returns:
- a CompletableFuture of a response
-
asObjectAsync
public <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> asObjectAsync(java.lang.Class<? extends T> responseClass, Callback<T> callback)
Description copied from interface:HttpRequestExecutes the request asynchronously, mapping to a type via the configured object mapper and then passed to a callback handler.- Specified by:
asObjectAsyncin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the return type- Parameters:
responseClass- the type for the ObjectMapper to map tocallback- a callback for handling the body post mapping- Returns:
- a CompletableFuture of a HttpResponse containing the body of T
-
asObjectAsync
public <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> asObjectAsync(GenericType<T> genericType)
Description copied from interface:HttpRequestExecutes the request asynchronously, and use a GenericType with the ObjectMapper- Specified by:
asObjectAsyncin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the type of the response- Parameters:
genericType- the generic type containing the type- Returns:
- a CompletableFuture of a HttpResponse containing the body of T
-
asObjectAsync
public <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> asObjectAsync(GenericType<T> genericType, Callback<T> callback)
Description copied from interface:HttpRequestExecutes the request asynchronously, and use a GenericType with the ObjectMapper- Specified by:
asObjectAsyncin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the type of the response- Parameters:
genericType- the generic type containing the typecallback- a callback for handling the body post mapping- Returns:
- a CompletableFuture of a HttpResponse containing the body of T
-
funcResponse
private <T> java.util.function.Function<RawResponse,HttpResponse<T>> funcResponse(java.util.function.Function<RawResponse,T> function)
-
thenConsume
public void thenConsume(java.util.function.Consumer<RawResponse> consumer)
Description copied from interface:HttpRequestExecute the request and pass the raw response to a consumer. This raw response contains the original InputStream and is suitable for reading large responses- Specified by:
thenConsumein interfaceHttpRequest<R extends HttpRequest>- Parameters:
consumer- a consumer function
-
thenConsumeAsync
public void thenConsumeAsync(java.util.function.Consumer<RawResponse> consumer)
Description copied from interface:HttpRequestExecute the request asynchronously and pass the raw response to a consumer. This raw response contains the original InputStream and is suitable for reading large responses- Specified by:
thenConsumeAsyncin interfaceHttpRequest<R extends HttpRequest>- Parameters:
consumer- a consumer function
-
asFile
public HttpResponse<java.io.File> asFile(java.lang.String path, java.nio.file.CopyOption... copyOptions)
Description copied from interface:HttpRequestExecutes the request and writes the contents into a file- Specified by:
asFilein interfaceHttpRequest<R extends HttpRequest>- Parameters:
path- The path to the file.copyOptions- options specifying how the copy should be done- Returns:
- a HttpResponse with the file containing the results
-
asFileAsync
public java.util.concurrent.CompletableFuture<HttpResponse<java.io.File>> asFileAsync(java.lang.String path, java.nio.file.CopyOption... copyOptions)
Description copied from interface:HttpRequestasynchronously executes the request and writes the contents into a file- Specified by:
asFileAsyncin interfaceHttpRequest<R extends HttpRequest>- Parameters:
path- The path to the file.copyOptions- options specifying how the copy should be done- Returns:
- a file containing the results
-
asFileAsync
public java.util.concurrent.CompletableFuture<HttpResponse<java.io.File>> asFileAsync(java.lang.String path, Callback<java.io.File> callback, java.nio.file.CopyOption... copyOptions)
Description copied from interface:HttpRequestasynchronously executes the request and writes the contents into a file- Specified by:
asFileAsyncin interfaceHttpRequest<R extends HttpRequest>- Parameters:
path- The path to the file.callback- a callback for handling the body post mappingcopyOptions- options specifying how the copy should be done- Returns:
- a file containing the results
-
asPaged
public <T> PagedList<T> asPaged(java.util.function.Function<HttpRequest,HttpResponse> mappingFunction, java.util.function.Function<HttpResponse<T>,java.lang.String> linkExtractor)
Description copied from interface:HttpRequestAllows for following paging links common in many APIs. Each request will result in the same request (headers, etc) but will use the "next" link provided by the extract function.- Specified by:
asPagedin interfaceHttpRequest<R extends HttpRequest>- Type Parameters:
T- the type of response.- Parameters:
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 paging- Returns:
- a PagedList of your type
-
request
private <E> HttpResponse<E> request(java.util.function.Function<RawResponse,HttpResponse<E>> transformer, java.lang.Class<?> resultType)
-
requestAsync
private <T> java.util.concurrent.CompletableFuture<HttpResponse<T>> requestAsync(HttpRequest request, java.util.function.Function<RawResponse,HttpResponse<T>> transformer, java.util.concurrent.CompletableFuture<HttpResponse<T>> callback, java.lang.Class<?> resultType)
-
getConsumer
private java.util.function.Function<RawResponse,HttpResponse<java.lang.Object>> getConsumer(java.util.function.Consumer<RawResponse> consumer)
-
getHttpMethod
public HttpMethod getHttpMethod()
- Specified by:
getHttpMethodin interfaceHttpRequest<R extends HttpRequest>- Returns:
- The HTTP method of the request
-
getUrl
public java.lang.String getUrl()
- Specified by:
getUrlin interfaceHttpRequest<R extends HttpRequest>- Returns:
- The current URL string for the request
-
getHeaders
public Headers getHeaders()
- Specified by:
getHeadersin interfaceHttpRequest<R extends HttpRequest>- Returns:
- the current headers for the request
-
getObjectMapper
protected ObjectMapper getObjectMapper()
-
getRequestTimeout
public java.lang.Integer getRequestTimeout()
- Specified by:
getRequestTimeoutin interfaceHttpRequest<R extends HttpRequest>- Returns:
- the connect timeout for this request
-
toSummary
public HttpRequestSummary toSummary()
- Specified by:
toSummaryin interfaceHttpRequest<R extends HttpRequest>- Returns:
- a summary for the response, used in metrics
-
getCreationTime
public java.time.Instant getCreationTime()
- Specified by:
getCreationTimein interfaceHttpRequest<R extends HttpRequest>- Returns:
- the instant the request object was created in UTC (not when it was sent).
-
getVersion
public java.net.http.HttpClient.Version getVersion()
Description copied from interface:HttpRequestgets the version for the request, or null if not set.- Specified by:
getVersionin interfaceHttpRequest<R extends HttpRequest>- Returns:
- the version
-
valueOr
private <T> T valueOr(T x, java.util.function.Supplier<T> o)
-
getPath
Path getPath()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-