1. Domino REST
  2. Getting started
  3. Quick start

Quick start

Prerequisites

  • Java 11 or higher.
  • Maven 3.6.0 or higher.

Adding domino-rest to your GWT project is quite simple, just follow these steps to get started with using domino-rest :

Steps

  • Add the library and processors dependencies to your project
    			<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>
    		
  • If you are using domino-rest with GWT then you will need to add the following inherit directive to your project .gwt.xml file
    			<inherits name="org.dominokit.rest.Rest"/>
    
    		
  • In your application entry point or main class initialize domino-rest:
    			DominoRestConfig.initDefaults();
    
    		
  • Assuming you have the following POJO:
    			@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.

  • Write the service definition interface :

    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);
    }
    
    		
  • Using the generated clients :

    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();
    
    		

We are a group of passionate people who love what we do

Donate & Support Us