In this article
MicroProfile Rest Client
This module lets us implement a simple client for a Restful service that we need to consume. We just need to create an interface with JAX-RS annotations describing the behavior of the Restful service.
@Path("/stock") public interface StockClient { @GET @Produces(MediaType.APPLICATION_JSON) List getAll(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/status/{status}") List getByStatus(@PathParam("status")String status); @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) Stock findById(@PathParam("id") String id); }
And then, we can use the RestClientBuilder and our client interface to generate a proxy instance to call the methods in a nicer way.
public Stock getStock(String id){ URI apiUri = getURI(); StockClient stockClient = RestClientBuilder.newBuilder() .baseUri(apiUri) .build(StockClient.class); return stockClient.findById(id); }
Table of contents: