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.
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.
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.
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.
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.
This example uses the web client to send a request with query params using the fluent API and log the response.
This example is pretty much similar to the query params example, however it leverages Vert.x URI Templates to encode the query parameters in the request URI.
First you need to run the server then you can run the client.
The server logs the query string on the console.
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.
The web client is able to send various kinds of bodies to the server.
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.
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.
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.
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.
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.
This examples shows how to send a vertx read stream with the web client.
The web client takes care of setting up the pipe between the read stream and the http client request.
First you need to run the server then you can run the client.
The web client can unmarshall response bodies to various formats.
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.
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.
This examples shows how to download an oauth2 protected resource, the example makes use of 2 requests:
-
first acquire a OAUTH2 access token
-
get the resource using the token
This example shows how to utilise the OAuth2WebClient which simplifies the process of acquiring and managing an OAuth2 access token and using it to access a protected resource.
First you configure the OAuth2 flow and then you create the client using the specified configuration. When sending request to the protected resource, the client will automatically acquire the token if it is not already available or is expired. Flow that will be used to acquire the token is specified per request.