In a previous post, we have covered consuming RESTful APIs with Vertx HttpClient and WebClient. In this post, we will consuming the GraphQL APIs we created in the last post.

Photo by Sam Balye on Unsplash

Firstly, let’s review the difference between the HttpClient and WebClient.

  • The HttpClient is a low level API, which provides fine-grained control to interact with the Http Server.
  • The WebClient is a high level API, which provides more convenient approaches to simplify handling web request and response. …


We have discussed GraphQL in a former Quarkus GraphQL post. In this post, we will explore the GraphQL support in Eclipse Vertx.

Photo by Yang Shuo on Unsplash

Quarkus also includes an alternative GraphQL extension which use the Eclipse Vertx GraphQL feature.

Follow the steps in the Building RESTful APIs with Eclipse Vertx and create a new Eclipse Vertx project, do not forget to add GraphQL into Dependencies.

Or add the following dependency into the existing pom.xml file directly.

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-graphql</artifactId>
</dependency>

Checkout the complete sample codes from my Github.

Vertx provides a specific GraphQLHandler to handle GraphQL request from client.

Fill the MainVerticle with the following content.

@Slf4j
public class MainVerticle extends AbstractVerticle…


In the Spring integration post, we use Spring to assemble the resources and start up the application.

Photo by 昊蓝 毛 on Unsplash

In this post, we will reuse the Spring base codes, but:

  • Use Hibernate Reactive to replace the raw Postgres Client
  • and use SmallRye Mutiny Vertx bindings to replace the original Vertx API, eg. Future etc..

Add the Hibernate related dependencies into the project pom.xml file.

<dependency>
<groupId>org.hibernate.reactive</groupId>
<artifactId>hibernate-reactive-core</artifactId>
<version>${hibernate-reactive.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>

In the above codes,

  • The hibernate-reactive-core provides Hibernate Reactive which use Vertx Postgres Client, etc to implement reactive APIs, currently it supports Java 8…


In the last post, we introduced a simple approach to integrate Vertx applications with Spring framework. In this post, we will try to integrate Vertx application with CDI to replace Spring.

Photo by Robynne Hu on Unsplash

CDI is a Dependency and Injection specification which is introduced in Java EE 6, currently Java EE is renamed to Jakarta EE and maintained by Eclipse Foundation. Weld is a compatible provider of the Jakarta CDI specification.

Add the following dependencies.

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<version>${weld.version}</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.2.3.Final</version>
</dependency>

In the above codes:

  • The weld-se-shaded provides a CDI runtime environment for Java SE platform.
  • The jandex will…

As shown in the former we assembled everything manually in the MainVerticle class. We will use Spring IOC to manage the dependencies.

Photo by Hanson Lu on Unsplash

For example, it looks like the following.

//Create a PgPool instance
var pgPool = pgPool();
//Creating PostRepository
var postRepository = PostRepository.create(pgPool);
//Creating PostHandler
var postHandlers = PostsHandler.create(postRepository);
// Initializing the sample data
var initializer = DataInitializer.create(pgPool);
initializer.run();
// Configure routes
var router = routes(postHandlers);
// Create the HTTP server
vertx.createHttpServer()...

In this post, we will introduce Spring framework to manage the dependencies of the above items.

Add the Spring context dependency into the project pom.xml file.

<dependency>…


In the last post, we rebuild the example application with Kotlin language. Besides basic language support, Eclipse Vertx’s Kotlin bindings provides Kotlin extensions to convert Vertx’s Future to Kotlin Coroutines.

Photo by Yuzki Wang on Unsplash

Follow the steps in the last post to create a Kotlin based Vertx project, we will rebuild the project with Kotlin Coroutines.

Firstly let’s have a look at the PostRepository.

class PostRepository(private val client: PgPool) {    suspend fun findAll() = client.query("SELECT * FROM posts ORDER BY id ASC")
.execute()
.map { rs: RowSet<Row?> ->
StreamSupport.stream(rs.spliterator(), false)
.map { mapFun(it!!) }
.toList()
}.await()
suspend fun findById(id: UUID)…


As mentioned in the former posts, Eclipse Vertx expands its API to different languages such as Kotlin, Groovy via official bindings, and even Node/Typescript and PHP via community supports.

Photo by Ben Gao on Unsplash

In this post, we will re-implement the former RESTful APIs with Kotlin language.

Open your browser and navigate to Eclipse Vertx Starter, and generate the project skeleton. Do not forget to select Kotlin in the language field.

For the existing project, add the following dependency into the pom.xml file.

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-lang-kotlin</artifactId>
</dependency>

Configure kotlin-compiler-plugin to compile the Kotlin source codes.

<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>…


Eclipse Vertx has a great codegen mechanism to bring its Event Loop based asynchronous programming model to diverse platforms, including other asynchronous libraries, such as RxJava2/3 and SmallRye Mutiny and different languages, such as Kotlin, Kotlin Coroutines, and even Node/Typescript, PHP etc.

Photo by Mèng Jiǎ on Unsplash

In this post, we will refactor the RESTful APIs we have done in the last post and reimplement it with RxJava 3. RxJava 3 fully implements Reactive Steams specification.

Open your browser, go to Vertx Starter, create a Vertx project skeleton. Do not forget to add RxJava 3 to the dependencies.

If you are working on an existing…


We have discussed how to build RESTful APIs with the basic Eclipse Vertx Web feature. In this post, we will cover how to create a Http Client and interact with RESTful APIs.

Photo by Joshua Earle on Unsplash

Similar to the creating of HttpServer, you can create a HttpClient from Vertx instance.

var options = new HttpClientOptions()
.setDefaultPort(8888);
var client = vertx.createHttpClient(options);

Then you can send request to the server like the following.

client.request(HttpMethod.GET, "/hello")
.compose(req -> req.send().compose(HttpClientResponse::body))
.onSuccess(...)
.onFailure(...)

The HttpClient is a low-level APIs and provides find-grained control of the request and response info. …


In the last post, we have built a simple RESTful APIs example application using Eclipse Vertx. In this post, we will discuss web related topic, such as exception handling and input validation, etc.

Photo by Patrick Xu on Unsplash

Vertx’s Future includes some hooks to be executed when the asynchronous flow is done.

  • onComplete will in invoked when the execution is completed, either it is succeeded or failed.
  • onSuccess handles the successful result.
  • onFailure catches the exception thrown in the execution.

Let’s explore how to handle the exceptions in the former example application.

Assume retrieving Post via a none-existing id, throw a PostNotFoundException instead of returning…

Hantsy

Self-employed technical consultant, solution architect and full-stack developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store