Interface HttpClient
- All Superinterfaces:
AutoCloseable
,Closeable
,LifeCycle<HttpClient>
- All Known Subinterfaces:
JdkHttpClient
,StreamingHttpClient
- All Known Implementing Classes:
DefaultHttpClient
,DefaultJdkHttpClient
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionThe default error type. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpClient
Create a newHttpClient
.static HttpClient
create
(@Nullable URL url, @NonNull HttpClientConfiguration configuration) Create a newHttpClient
with the specified configuration.default <I> Publisher<HttpResponse<ByteBuffer>>
exchange
(@NonNull HttpRequest<I> request) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
.default <I,
O> Publisher<HttpResponse<O>> exchange
(@NonNull HttpRequest<I> request, @NonNull Argument<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.<I,
O, E> Publisher<HttpResponse<O>> exchange
(@NonNull HttpRequest<I> request, @NonNull Argument<O> bodyType, @NonNull Argument<E> errorType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.default <I,
O> Publisher<HttpResponse<O>> exchange
(@NonNull HttpRequest<I> request, @NonNull Class<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.default Publisher<HttpResponse<ByteBuffer>>
Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher
.default <O> Publisher<HttpResponse<O>>
Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher
.default HttpClient
refresh()
Refreshes the current life cycle object.retrieve
(@NonNull HttpRequest<I> request) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.default <I,
O> Publisher<O> retrieve
(@NonNull HttpRequest<I> request, @NonNull Argument<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.default <I,
O, E> Publisher<O> retrieve
(@NonNull HttpRequest<I> request, @NonNull Argument<O> bodyType, @NonNull Argument<E> errorType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.default <I,
O> Publisher<O> retrieve
(@NonNull HttpRequest<I> request, @NonNull Class<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.
-
Field Details
-
DEFAULT_ERROR_TYPE
The default error type.
-
-
Method Details
-
toBlocking
BlockingHttpClient toBlocking()- Returns:
- A blocking HTTP client suitable for testing and non-production scenarios.
-
exchange
<I,O, Publisher<HttpResponse<O>> exchangeE> (@NonNull @NonNull HttpRequest<I> request, @NonNull @NonNull Argument<O> bodyType, @NonNull @NonNull Argument<E> errorType) Perform an HTTP request for the given request object emitting the full HTTP response from returned
Publisher
and converting the response body to the specified type.This method will send a
Content-Length
header and except a content length header the response and is designed for simple non-streaming exchanges of dataBy default the exchange
Content-Type
is application/json, unless otherwise specified in the passedHttpRequest
- Type Parameters:
I
- The request body typeO
- The response body typeE
- The error type- Parameters:
request
- TheHttpRequest
to executebodyType
- The body typeerrorType
- The error type- Returns:
- A
Publisher
that emits the fullHttpResponse
object
-
exchange
default <I,O> Publisher<HttpResponse<O>> exchange(@NonNull @NonNull HttpRequest<I> request, @NonNull @NonNull Argument<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returned
Publisher
and converting the response body to the specified type.This method will send a
Content-Length
header and except a content length header the response and is designed for simple non-streaming exchanges of dataBy default the exchange
Content-Type
is application/json, unless otherwise specified in the passedHttpRequest
- Type Parameters:
I
- The request body typeO
- The response body type- Parameters:
request
- TheHttpRequest
to executebodyType
- The body type- Returns:
- A
Publisher
that emits the fullHttpResponse
object
-
exchange
Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
.- Type Parameters:
I
- The request body type- Parameters:
request
- TheHttpRequest
to execute- Returns:
- A
Publisher
that emits the fullHttpResponse
object
-
exchange
Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher
.- Parameters:
uri
- The Uri- Returns:
- A
Publisher
that emits the fullHttpResponse
object
-
exchange
default <O> Publisher<HttpResponse<O>> exchange(@NonNull @NonNull String uri, @NonNull @NonNull Class<O> bodyType) Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher
.- Type Parameters:
O
- The response body type- Parameters:
uri
- The request URIbodyType
- The body type- Returns:
- A
Publisher
that emits the fullHttpResponse
object
-
exchange
default <I,O> Publisher<HttpResponse<O>> exchange(@NonNull @NonNull HttpRequest<I> request, @NonNull @NonNull Class<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.- Type Parameters:
I
- The request body typeO
- The response body type- Parameters:
request
- TheHttpRequest
to executebodyType
- The body type- Returns:
- A
Publisher
that emits the fullHttpResponse
object
-
retrieve
default <I,O, Publisher<O> retrieveE> (@NonNull @NonNull HttpRequest<I> request, @NonNull @NonNull Argument<O> bodyType, @NonNull @NonNull Argument<E> errorType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.- Type Parameters:
I
- The request body typeO
- The response body typeE
- The error type- Parameters:
request
- TheHttpRequest
to executebodyType
- The body typeerrorType
- The error type- Returns:
- A
Publisher
that emits a result of the given type
-
retrieve
default <I,O> Publisher<O> retrieve(@NonNull @NonNull HttpRequest<I> request, @NonNull @NonNull Argument<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.- Type Parameters:
I
- The request body typeO
- The response body type- Parameters:
request
- TheHttpRequest
to executebodyType
- The body type- Returns:
- A
Publisher
that emits a result of the given type
-
retrieve
default <I,O> Publisher<O> retrieve(@NonNull @NonNull HttpRequest<I> request, @NonNull @NonNull Class<O> bodyType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.- Type Parameters:
I
- The request body typeO
- The response body type- Parameters:
request
- TheHttpRequest
to executebodyType
- The body type- Returns:
- A
Publisher
that emits a result of the given type
-
retrieve
Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.- Type Parameters:
I
- The request body type- Parameters:
request
- TheHttpRequest
to execute- Returns:
- A
Publisher
that emits String result
-
retrieve
Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.- Parameters:
uri
- The URI- Returns:
- A
Publisher
that emits String result
-
refresh
Description copied from interface:LifeCycle
Refreshes the current life cycle object. Effectively this callsLifeCycle.stop()
followed byLifeCycle.start()
.- Specified by:
refresh
in interfaceLifeCycle<HttpClient>
- Returns:
- This lifecycle component
-
create
Create a newHttpClient
. Note that this method should only be used outside of the context of a Micronaut application. The returnedHttpClient
is not subject to dependency injection. The creator is responsible for closing the client to avoid leaking connections. Within a Micronaut application useInject
to inject a client instead.- Parameters:
url
- The base URL- Returns:
- The client
-
create
static HttpClient create(@Nullable @Nullable URL url, @NonNull @NonNull HttpClientConfiguration configuration) Create a newHttpClient
with the specified configuration. Note that this method should only be used outside of the context of an application. Within Micronaut useInject
to inject a client instead- Parameters:
url
- The base URLconfiguration
- the client configuration- Returns:
- The client
- Since:
- 2.2.0
-