mini-rest-client

A Kotlin Mimimal REST client

Лицензия

Лицензия

Категории

Категории

CLI Взаимодействие с пользователем
Группа

Группа

com.github.barakb
Идентификатор

Идентификатор

mini-rest-client
Последняя версия

Последняя версия

1.0.5
Дата

Дата

Тип

Тип

jar
Описание

Описание

mini-rest-client
A Kotlin Mimimal REST client
Ссылка на сайт

Ссылка на сайт

https://github.com/barakb/mini-rest-client
Система контроля версий

Система контроля версий

https://github.com/barakb/mini-rest-client

Скачать mini-rest-client

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.barakb/mini-rest-client/ -->
<dependency>
    <groupId>com.github.barakb</groupId>
    <artifactId>mini-rest-client</artifactId>
    <version>1.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.barakb/mini-rest-client/
implementation 'com.github.barakb:mini-rest-client:1.0.5'
// https://jarcasting.com/artifacts/com.github.barakb/mini-rest-client/
implementation ("com.github.barakb:mini-rest-client:1.0.5")
'com.github.barakb:mini-rest-client:jar:1.0.5'
<dependency org="com.github.barakb" name="mini-rest-client" rev="1.0.5">
  <artifact name="mini-rest-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.barakb', module='mini-rest-client', version='1.0.5')
)
libraryDependencies += "com.github.barakb" % "mini-rest-client" % "1.0.5"
[com.github.barakb/mini-rest-client "1.0.5"]

Зависимости

runtime (7)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlinx : kotlinx-coroutines-core-jvm jar 1.4.1
org.apache.httpcomponents.client5 : httpclient5 jar 5.0.1
com.google.code.gson : gson jar 2.8.6
org.slf4j : slf4j-api jar 1.7.30
io.github.microutils : kotlin-logging jar 1.8.3
org.jetbrains.kotlin : kotlin-reflect jar 1.4.20
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.20

Модули Проекта

Данный проект не имеет модулей.

Build Status Download Maven Central GitHub License

A Kotlin Minimal REST client

I had 3 goals in mind when starting this work.

  1. Fully async code no blocking threads.
  2. Easy to compose both sequentially and concurrently
  3. Minimum dependencies.
  4. Small
  • Choosing the underlining http client to be Apache HttpAsyncClient satisfy the first and third requirements.
  • Extending CloseableHttpAsyncClient.execute as a suspend function (in the file CloseableHttpAsyncClientExt.kt) enable easy composition of the result client sequentially and concurrently, hence satisfy the second requirement.

To consume this project using maven add the following to your pom.xml

<dependency>
     <groupId>com.github.barakb</groupId>
     <artifactId>mini-rest-client</artifactId>
     <version>1.0.5</version>
</dependency>

Or gradle

implementation("com.github.barakb:mini-rest-client:1.0.5")
Usage:

To create a Nomad client Kotlin DSL can be used.

fun main(): Unit = runBlocking {
    HttpClient {
        defaultRequest {
            url = "http://httpbin.org/"
            header("name", "value")
            param("v", "f")
        }
    }.use { client ->
        val headers = client.get<JsonObject> {
            path = "headers"
        }
        println("headers: $headers")
    }
}

Inside the client DLS you have full access to the underline HttpAsyncClientBuilder, so it is easy to configure

client {
}

The client uses the return type to extract the result form the http response.

News:

With version 1.0.5 it is possible to set the connectTimeout and the responseTimeout per request

@ExperimentalTime
fun main(): Unit = runBlocking {
    HttpClient {
        gson { setPrettyPrinting() }
        defaultRequest {
            contentType = ContentType.APPLICATION_JSON
            url = "http://httpbin.org/"
            header("name", "value")
            param("v", "f")
        }
    }.use { client ->
        val headers = client.get<Headers> {
            path = "headers"
            connectTimeout = 15.seconds
            responseTimeout = 30.seconds
        }
        println("headers: $headers")
    }
}

data class Headers(@HttpHeader("host") var host: String?, val headers: JsonObject)

Версии библиотеки

Версия
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0