1 Star 0 Fork 2

周周/vertx-examples

forked from githubsync/vertx-examples 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README.adoc 5.63 KB
一键复制 编辑 原始数据 按行查看 历史
Paulo Lopes 提交于 2017-07-18 21:17 . Add example to doc

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

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhouzq2046/vertx-examples.git
git@gitee.com:zhouzq2046/vertx-examples.git
zhouzq2046
vertx-examples
vertx-examples
4.x

搜索帮助