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) 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.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.withTimeout
(Duration timeout)
-
Method Details
-
withRequest
-
addHeader
-
addHeader
-
withHeaders
-
addCredentials
-
withTimeout
-
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 -
invokeAsync
CompletionStage<StrictResponse<R>> invokeAsync() -
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
-
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
-