项目作者: kvarto

项目描述 :
Kotlin, vertx, microservices utils
高级语言: Kotlin
项目地址: git://github.com/kvarto/kvarto.git
创建时间: 2019-11-10T12:44:22Z
项目社区:https://github.com/kvarto/kvarto

开源协议:

下载


Kvarto

Kvarto is set of utilities for writing REST services using Kotlin and Vertx. It makes extensive use of coroutines
and aims at providing clean, minimal, intuitive interface for sending and receiving http requests.

Kvarto includes http client, http server and various helpers. It supports metrics with micrometer and tracing with
open-tracing.

Http Client

HttpClient provides single method send that accepts HttpRequest and returns HttpResponse.
HttpRequest is descriptive data structure that represents all data needed to send http request like
url, method, parameters, headers, body and metadata like timeout, circuit breaker config, retries etc.
HttpResponse is descriptive data structure that represents http server response, It contains response status,
headers and body.

Both request and response have streaming support: theie bodies can be converted to Flow<ByteArray>.

Client example:

  1. val client = HttpClient.create(vertx)
  2. val request = HttpRequest(URL("http://httpbin.org"))
  3. .addParameter("foo", "bar")
  4. .addHeader("Zig", "zag")
  5. .withTimeout(300.millis)
  6. .withSuccessStatuses(setOf(HttpStatus.OK, HttpStatus.CONFLICT))
  7. val response = client.send(request)
  8. println(response.body.asString())

Http Server