Latest commit 758915b Jul 11, 2018

README.adoc

Vert.x Web-Client examples

Here you will find examples demonstrating Vert.x Web Client in action.

Vert.x Web Client is an asynchronous HTTP and HTTP/2 client. Please consult the Vert.x Web Client manual for detailed documentation on Vert.x Web Client.

Logging

When running in an IDE you can edit src/main/resources/vertx-default-jul-logging.properties to configure logging. Trace logging is enabled for Vert.x Web Client classes so you can easily trace requests as they are routed through different handlers.

Dependencies required

To use Vert.x Web Client in your own Maven or Gradle project you will need following dependencies

Group ID: io.vertx
Artifact ID: vertx-core

and

Group ID: io.vertx
Artifact ID: vertx-web-client

If you’re using a template engine you will also need to add the engine dependency explicitly, depending on the engine you are using.

Simple

This example uses the web client to send a request and log the response.

First you need to run the server then you can run the client.

Query params

This example uses the web client to send a request with query params using the fluent API and log the response.

First you need to run the server then you can run the client.

The server logs the query string on the console.

The client add several query parameters to the http request with the fluent API, the client takes care of encoding the parameters.

HTTPS

This example is like the simple example but shows how to configure the client for sending SSL/TLS requests.

First you need to run the server then you can run the client.

Sending bodies

The web client is able to send various kinds of bodies to the server.

Hello World

This examples shows how to send a body with "Hello World" with the web client.

First you need to run the server then you can run the client.

Sending a form

This examples shows how to send a form with the web client.

First you need to run the server then you can run the client.

Sending a json object

This examples shows how to send a json object with the web client.

First you need to run the server then you can run the client.

Sending a POJO mapped to json

This examples shows how to send a simple java object encoded as a json object with the web client.

First you need to run the server then you can run the client.

Sending a multipart form

This examples shows how to send a multipart form with the web client.

First you need to run the server then you can run the client.

Sending a stream

This examples shows how to send a vertx read stream with the web client.

The web client takes care of setting up the pump between the read stream and the http client request.

First you need to run the server then you can run the client.

Receiving response bodies

The web client can unmarshall response bodies to various formats.

Receiving a json object body

This examples shows how to decode a json object body with the web client.

First you need to run the server then you can run the client.

Receiving a POJO mapped to json

This examples shows how to decode a json object body to a simple java object with the web client.

First you need to run the server then you can run the client.

Receiving a OAUTH2 protected resource

This examples shows how to download a oauth2 protected resource, the example makes use of 2 requests:

  • first acquire a OAUTH2 access token

  • get the resource using the token