Package akka.javasdk.http
Interface RequestBuilder<R>
- Type Parameters:
R
- The type the response body will be parsed into
@DoNotInherit
public interface RequestBuilder<R>
A builder for HTTP requests and handling of their responses
Not for user extension, use HttpClient
to get an instance
-
Method Summary
Modifier and TypeMethodDescriptionaddCredentials
(akka.http.javadsl.model.headers.HttpCredentials credentials) addHeader
(akka.http.javadsl.model.HttpHeader header) addQueryParameter
(String key, String value) invoke()
modifyRequest
(Function<akka.http.javadsl.model.HttpRequest, akka.http.javadsl.model.HttpRequest> adapter) Transform the request before sending it.<T> RequestBuilder
<T> parseResponseBody
(Function<byte[], T> parse) Converts the response body to the specified type using the provided parser function.<T> RequestBuilder
<T> responseBodyAs
(Class<T> type) Converts the response body to the specified type.<T> RequestBuilder
<List<T>> responseBodyAsListOf
(Class<T> elementType) Converts the response body as a list of the specified type.withHeaders
(Iterable<akka.http.javadsl.model.HttpHeader> headers) withRequest
(akka.http.javadsl.model.HttpRequest request) withRequestBody
(byte[] bytes) Prepare for sending an HTTP request with an application/octet-stream body.withRequestBody
(akka.http.javadsl.model.ContentType type, byte[] bytes) Prepare for sending an HTTP request with an arbitrary payload encoded as described by the content typewithRequestBody
(Object object) Prepare for sending an HTTP request with an application/json body.withRequestBody
(String text) Prepare for sending an HTTP request with a text/plain body.withRetry
(int maxRetries) Set the retry settings for this call.withRetry
(akka.pattern.RetrySettings retrySettings) Set the retry settings for this call.withTimeout
(Duration timeout)
-
Method Details
-
withRequest
-
addHeader
-
addHeader
-
withHeaders
-
addCredentials
-
withTimeout
-
addQueryParameter
-
modifyRequest
RequestBuilder<R> modifyRequest(Function<akka.http.javadsl.model.HttpRequest, akka.http.javadsl.model.HttpRequest> adapter) Transform the request before sending it. This method allows for extra request configuration. -
withRequestBody
Prepare for sending an HTTP request with an application/json body. The passed Object is serialized to json using the application's default Jackson serializer. -
withRequestBody
Prepare for sending an HTTP request with a text/plain body. -
withRequestBody
Prepare for sending an HTTP request with an application/octet-stream body. -
withRequestBody
Prepare for sending an HTTP request with an arbitrary payload encoded as described by the content type -
withRetry
Set the retry settings for this call.- Parameters:
retrySettings
- The retry settings
-
withRetry
Set the retry settings for this call. A predefined backoff strategy will be calculated based on the number of maxRetries.- Parameters:
maxRetries
- The number of retries to make
-
invokeAsync
CompletionStage<StrictResponse<R>> invokeAsync() -
invoke
StrictResponse<R> invoke() -
responseBodyAs
Converts the response body to the specified type.The response body payload is expected to be a JSON object and will be deserialized to the specified type using the application's default Jackson deserializer.
- Parameters:
type
- the expected class type of the response body- Returns:
- a RequestBuilder configured to produce a StrictResponse with a deserialized response body of type T
-
responseBodyAsListOf
Converts the response body as a list of the specified type.The response body payload is expected to be a JSON array and each element will be deserialized to the specified type using the application's default Jackson deserializer.
- Parameters:
elementType
- the expected class type of the response body- Returns:
- a RequestBuilder configured to produce a StrictResponse with a deserialized response body of type T
-
parseResponseBody
Converts the response body to the specified type using the provided parser function.- Parameters:
parse
- the function to parse the response body- Returns:
- a RequestBuilder configured to produce a StrictResponse with a deserialized response body of type T
-