August 2019
Intermediate to advanced
256 pages
6h 43m
English
To define the type-safe interface for an endpoint, we create a Java interface that leverages JAX-RS annotations to map interface methods to the REST endpoint they proxy. A basic example is illustrated in the following WorldClockApi interface:
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/json")public interface WorldClockApi { static final String BASE_URL = "http://worldclockapi.com/api/json"; @GET @Path("/utc/now") @Produces(MediaType.APPLICATION_JSON) Now utc(); @GET @Path("{tz}/now") @Produces(MediaType.APPLICATION_JSON) Now tz(@PathParam("tz") String tz);}public class Now ...Read now
Unlock full access