Interface HttpClient
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable,io.micronaut.context.LifeCycle<HttpClient>
- All Known Subinterfaces:
StreamingHttpClient
public interface HttpClient extends java.io.Closeable, io.micronaut.context.LifeCycle<HttpClient>
A non-blocking HTTP client interface designed around the Micronaut API and Reactive Streams.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static io.micronaut.core.type.Argument<io.micronaut.http.hateoas.JsonError>DEFAULT_ERROR_TYPEThe default error type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static HttpClientcreate(java.net.URL url)Create a newHttpClient.static HttpClientcreate(java.net.URL url, HttpClientConfiguration configuration)Create a newHttpClientwith the specified configuration.default <I> org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<io.micronaut.core.io.buffer.ByteBuffer>>exchange(io.micronaut.http.HttpRequest<I> request)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher.default <I,O>
org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>>exchange(io.micronaut.http.HttpRequest<I> request, io.micronaut.core.type.Argument<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.<I,O,E>
org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>>exchange(io.micronaut.http.HttpRequest<I> request, io.micronaut.core.type.Argument<O> bodyType, io.micronaut.core.type.Argument<E> errorType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.default <I,O>
org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>>exchange(io.micronaut.http.HttpRequest<I> request, java.lang.Class<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.default org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<io.micronaut.core.io.buffer.ByteBuffer>>exchange(java.lang.String uri)Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher.default <O> org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>>exchange(java.lang.String uri, java.lang.Class<O> bodyType)Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher.default HttpClientrefresh()default <I> org.reactivestreams.Publisher<java.lang.String>retrieve(io.micronaut.http.HttpRequest<I> request)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.default <I,O>
org.reactivestreams.Publisher<O>retrieve(io.micronaut.http.HttpRequest<I> request, io.micronaut.core.type.Argument<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.default <I,O,E>
org.reactivestreams.Publisher<O>retrieve(io.micronaut.http.HttpRequest<I> request, io.micronaut.core.type.Argument<O> bodyType, io.micronaut.core.type.Argument<E> errorType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.default <I,O>
org.reactivestreams.Publisher<O>retrieve(io.micronaut.http.HttpRequest<I> request, java.lang.Class<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.default org.reactivestreams.Publisher<java.lang.String>retrieve(java.lang.String uri)Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.BlockingHttpClienttoBlocking()
-
-
-
Method Detail
-
toBlocking
BlockingHttpClient toBlocking()
- Returns:
- A blocking HTTP client suitable for testing and non-production scenarios.
-
exchange
<I,O,E> org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>> exchange(@NonNull io.micronaut.http.HttpRequest<I> request, @NonNull io.micronaut.core.type.Argument<O> bodyType, @NonNull io.micronaut.core.type.Argument<E> errorType)Perform an HTTP request for the given request object emitting the full HTTP response from returned
Publisherand converting the response body to the specified type.This method will send a
Content-Lengthheader and except a content length header the response and is designed for simple non-streaming exchanges of dataBy default the exchange
Content-Typeis application/json, unless otherwise specified in the passedHttpRequest- Type Parameters:
I- The request body typeO- The response body typeE- The error type- Parameters:
request- TheHttpRequestto executebodyType- The body typeerrorType- The error type- Returns:
- A
Publisherthat emits the fullHttpResponseobject
-
exchange
default <I,O> org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>> exchange(@NonNull io.micronaut.http.HttpRequest<I> request, @NonNull io.micronaut.core.type.Argument<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returned
Publisherand converting the response body to the specified type.This method will send a
Content-Lengthheader and except a content length header the response and is designed for simple non-streaming exchanges of dataBy default the exchange
Content-Typeis application/json, unless otherwise specified in the passedHttpRequest- Type Parameters:
I- The request body typeO- The response body type- Parameters:
request- TheHttpRequestto executebodyType- The body type- Returns:
- A
Publisherthat emits the fullHttpResponseobject
-
exchange
default <I> org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<io.micronaut.core.io.buffer.ByteBuffer>> exchange(@NonNull io.micronaut.http.HttpRequest<I> request)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- TheHttpRequestto execute- Returns:
- A
Publisherthat emits the fullHttpResponseobject
-
exchange
default org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<io.micronaut.core.io.buffer.ByteBuffer>> exchange(@NonNull java.lang.String uri)Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisher.- Parameters:
uri- The Uri- Returns:
- A
Publisherthat emits the fullHttpResponseobject
-
exchange
default <O> org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>> exchange(@NonNull java.lang.String uri, @NonNull java.lang.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
Publisherthat emits the fullHttpResponseobject
-
exchange
default <I,O> org.reactivestreams.Publisher<io.micronaut.http.HttpResponse<O>> exchange(@NonNull io.micronaut.http.HttpRequest<I> request, @NonNull java.lang.Class<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.- Type Parameters:
I- The request body typeO- The response body type- Parameters:
request- TheHttpRequestto executebodyType- The body type- Returns:
- A
Publisherthat emits the fullHttpResponseobject
-
retrieve
default <I,O,E> org.reactivestreams.Publisher<O> retrieve(@NonNull io.micronaut.http.HttpRequest<I> request, @NonNull io.micronaut.core.type.Argument<O> bodyType, @NonNull io.micronaut.core.type.Argument<E> errorType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.- Type Parameters:
I- The request body typeO- The response body typeE- The error type- Parameters:
request- TheHttpRequestto executebodyType- The body typeerrorType- The error type- Returns:
- A
Publisherthat emits a result of the given type
-
retrieve
default <I,O> org.reactivestreams.Publisher<O> retrieve(@NonNull io.micronaut.http.HttpRequest<I> request, @NonNull io.micronaut.core.type.Argument<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.- Type Parameters:
I- The request body typeO- The response body type- Parameters:
request- TheHttpRequestto executebodyType- The body type- Returns:
- A
Publisherthat emits a result of the given type
-
retrieve
default <I,O> org.reactivestreams.Publisher<O> retrieve(@NonNull io.micronaut.http.HttpRequest<I> request, @NonNull java.lang.Class<O> bodyType)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.- Type Parameters:
I- The request body typeO- The response body type- Parameters:
request- TheHttpRequestto executebodyType- The body type- Returns:
- A
Publisherthat emits a result of the given type
-
retrieve
default <I> org.reactivestreams.Publisher<java.lang.String> retrieve(@NonNull io.micronaut.http.HttpRequest<I> request)Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.- Type Parameters:
I- The request body type- Parameters:
request- TheHttpRequestto execute- Returns:
- A
Publisherthat emits String result
-
retrieve
default org.reactivestreams.Publisher<java.lang.String> retrieve(@NonNull java.lang.String uri)Perform an HTTP GET request for the given request object emitting the full HTTP response from returnedPublisherand converting the response body to the specified type.- Parameters:
uri- The URI- Returns:
- A
Publisherthat emits String result
-
refresh
default HttpClient refresh()
- Specified by:
refreshin interfaceio.micronaut.context.LifeCycle<HttpClient>
-
create
static HttpClient create(@Nullable java.net.URL url)
Create a newHttpClient. Note that this method should only be used outside of the context of a Micronaut application. The returnedHttpClientis not subject to dependency injection. The creator is responsible for closing the client to avoid leaking connections. Within a Micronaut application useInjectto inject a client instead.- Parameters:
url- The base URL- Returns:
- The client
-
create
static HttpClient create(@Nullable java.net.URL url, @NonNull HttpClientConfiguration configuration)
Create a newHttpClientwith the specified configuration. Note that this method should only be used outside of the context of an application. Within Micronaut useInjectto inject a client instead- Parameters:
url- The base URLconfiguration- the client configuration- Returns:
- The client
- Since:
- 2.2.0
-
-