Adding domino-rest to your GWT project is quite simple, just follow these steps to get started with using domino-rest :
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-rest-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-rest-processor</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
If you are using annotationProcessorPaths to add processors dependencies, make sure you add the domino-rest-jaxrs path as well
<annotationProcessorPaths>
<path>
<groupId>org.dominokit</groupId>
<artifactId>domino-rest-processor</artifactId>
<version>2.0.0</version>
</path>
</annotationProcessorPaths>
<inherits name="org.dominokit.rest.Rest"/>
DominoRestConfig.initDefaults();
@JSONMapper
public class Movie {
@PathParam("name")
private String name;
private int rating;
private String bio;
private String releaseDate;
// setters and getters
}
A POJO used in the service definition as a response or request needs to be annotated with @JSONMapper otherwise domino-rest will assume it will be serialized/deserialized as a JSON using domino-jackson defaults.
Defining a service and generating the REST cliend can as easy as annotating a JAX-RS interface with @RequestFactory, once the interface is compiled domino-rest processor will generate a factory class that we can use to make REST requests.
@RequestFactory
public interface MoviesService {
@Path("library/movies/:movieName")
@GET
Movie getMovieByName(@PathParam("movieName") String movieName);
@Path("library/movies")
@GET
List<Movie> listMovies();
@Path("library/movies/:name")
@PUT
void updateMovie(@BeanParam @RequestBody Movie movie);
}
The generated client class will be named with the service interface name + Factory, get the instance and call the service method :
MoviesServiceFactory.INSTANCE
.getMovieByName("hulk")
.onSuccess(movie -> {
//do something on success
})
.onFailed(failedResponse -> {
//do something on error
})
.send();
MoviesServiceFactory.INSTANCE
.listMovies()
.onSuccess(movies -> {
//do something on success
})
.onFailed(failedResponse -> {
//do something on error
})
.send();
MoviesServiceFactory.INSTANCE
.updateMovie(movie)
.onSuccess(aVoid -> {
//do something on success
})
.onFailed(failedResponse -> {
//do something on error
})
.send();