1. Domino REST
  2. Rest clients
  3. Global interceptors

Global interceptors

Global interceptors allows us to intercept the requests/responses of domino-rest and modify the requests before they are sent to the server, or the response after it is received from the server.

  • Intercepting requests

    In many cases we might need to intercept all rest requests to add some extra headers, like security headers or authentication tokens, and it would be painful to do this for each request one at a time. and for this domino-rest allow defining global interceptors that can intercept all requests using DominoRestConfig. Example :

    			MoviesServiceFactory.INSTANCE
        .getMovieByName("hulk")
        .onSuccess(movie ->{})
        .send();
    
    		

    The request interceptors are blocking which allows us to do some other rest calls or async operation before resuming the request, requests will resume only after all interceptors calls the complete method of the contextWait received in the argument.

  • Intercepting responses

    We can use response interceptors to intercepts generic responses, like authentication or errors, and we can add as many response interceptors as we want. These hooks fire before the actual success/fail callbacks, and the fail handler can be skipped from an interceptor. Example:

    			@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
        @SuccessCodes({200})
        void updateMovie(@beanParam @RequestBody Movie movie);
    }
    
    		

    Use onBeforeSuccessCallback and onBeforeFailedCallback (instead of the deprecated interceptOnSuccess/interceptOnFailed) for per-outcome hooks. Completion hooks run for both paths: onBeforeCompleteCallback and onAfterCompleteCallback.

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

Donate & Support Us