O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MicroProfile REST Client programmatic API usage

MP-RC supports both programmatic lookup and CDI injection approaches for usage. An example of a REST service making use of org.eclipse.microprofile.rest.client.RestClientBuilder to create a type-safe client for the WorldClockApi interface is listed in the following as WorldClockUser.java:

package io.pckt.restc.contract;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;@Path("/api")@ApplicationScopedpublic class WorldClockUser { @GET @Path("/now-utc") @Produces(MediaType.TEXT_PLAIN) public String getCurrentDateTime() { WorldClockApi remoteApi = RestClientBuilder.newBuilder() .baseUri(URI.create(WorldClockApi.BASE_URL)) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required