Web Handler

All Webhandlers need to implement Handler.handle(RoutingContext ctx). In our implementation they all extend AbstractAPIHandler

JSON processing

When a request has no body (e.g. GET, DELETE) and expects the content type application/json or the request body/response both are application/json NO Web handler code needs to be written. The DefaultJsoHandler automatically takes care of this.

Only when the default processing doesn’t fit the API need a custom handler is needed

Custom Handlers

To extend the AbstractAPIHandler only 2 methods (and one constructor copied) need to get implemented. To prepare sending to the database handler:

  @Override
  protected JsonObject preparePayload(final RoutingContext ctx, final MultiMap header) {
    // TODO: Your code goes here ...
  }

To process the returned value

@Override
  protected void listenForResponse(final EventBusRequestObservable<T> observable, final RoutingContext ctx) {
    // TODO: Your code goes here ... 
  }

The method needs to subscribe to the observable and send data back using the response retrieved from the RoutingContext.

Observable.create(observable).subscribe(
        value -> {
        // Your code goes here for values
        },
        error -> {
        // Your code goes here for an error
        },
        () -> {
        // Your code goes here for end of data
        });

Helper functions

  • To simply collect all parameters you can use payloadFromAllParams(ctx, header);
  • To add data to a returned JSON before it gets sent use injectIntoObservableValue(value)
  • Signal an error using endWithError

Handler Flags

Ovwerwrite the method getReqOptions() to alter the conditions like required authorization or default database. Check the ENUM RequestOptionFlags for available details