Eclipse MicroProfile Rest Client API
Since Payara Server 4.1.2.182 and 5.182
Provided version of the API: MicroProfile Rest Client 1.2
Background
The MicroProfile Rest Client provides a type-safe approach to invoke RESTful services over HTTP. An aim of this specification is to provide a much more natural coding style, with the underlying MicroProfile implementation handling the communication between the client and service.
The Eclipse MicroProfile Rest Client repository contains a number of examples and information about how to use this API.
CDI
Full MicroProfile documentation available here
Rest Client interfaces may be injected as CDI beans. To do this, you must first register your interface class by using the @RegisterRestClient
annotation, and then use the @RestClient
qualifier on the injected bean, like so:
@RegisterRestClient
public interface MyServiceClient {
@GET
@Path("/greet")
Response greet();
}
@ApplicationScoped
public class MyService {
@Inject
@RestClient
private MyServiceClient client;
}
Async
Full MicroProfile documentation available here
It is possible for Rest Client interface methods to be declared asynchronous. This allows the thread invoking the interface method to proceed while the RESTful request occurs on another thread.
Any method of the interface class is deemed an asynchonronous method if it has a return type of CompletionStage
.
Providers
Full MicroProfile documentation available here
The RestClientBuilder
interface extends the Configurable
interface from JAX-RS, allowing a user to register custom providers while it’s being built. Payara Server and Micro support the following provider types:
-
ClientRequestFilter
-
ClientResponseFilter
-
MessageBodyReader
-
MessageBodyWriter
-
ParamConverter
-
ReaderInterceptor
-
WriterInterceptor
-
ResponseExceptionMapper
See the full MicroProfile documentation for the registration methods.