vertx-rest

Logo

Writing vertx rest application based on JAX-RS applications

View the Project on GitHub dream11/vertx-rest

vertx-rest

Continuous Integration Code Coverage License

Overview

Setup

Add the following dependency to the dependencies section of your build descriptor:

Note: Replace x.y.z above with one of the released versions

Usage

Create Rest Verticle

Create the application REST Verticle by extending com.dream11.rest.AbstractRestVerticle class. The AbstractRestVerticle here does the following:

public class RestVerticle extends AbstractRestVerticle {
    
  public RestVerticle() {
    // starts http server with default options
    // All classes with @Path annotation in the specified package are registered with the router
    super("com.dream11.package"); 
  }
  
  @Override
  protected ClassInjector getInjector() {
    // Add your implmentation of injector
    return null;
  }
}

Use the following constructor to pass custom HTTP Server Options

public RestVerticle() {
  super("com.dream11.package", new HttpServerOptions().setPort(8080)); // starts http server with provided options
}

Create a Rest Resource

@Path("/test")
public class TestRoute {

  @GET
  @Consumes(MediaType.WILDCARD)
  @Produces(MediaType.APPLICATION_JSON)
  @ApiResponse(content = @Content(schema = @Schema(implementation = String.class)))
  public CompletionStage<String> test() {
    return Single.just("Hello World")
            .toCompletionStage();
  }
}

Validations

Exception Handling

Timeouts

Dependency Injection

Custom Providers

Custom Json Provider

You can create custom json providers by

Examples

Please refer tests for an example application

Swagger Specification

Follow this doc to generate swagger specification.

References