This Android library provides a Ktor HTTP client engine that integrates with the Karoo System Service, introduced by Karoo Extensions. It enables seamless HTTP requests within applications using the Karoo APIs.
- Provides a Ktor
HttpClientEngine
that works with Karoo System Service. - Supports custom timeouts for HTTP requests.
- Works even if the Karoo itself has no wifi connection. (Karoo Companion required)
- Only works with the new Hammerhead Karoo. Karoo 2 is not supported.
- Http Requests will always be sent through the Karoo System Service even though a network connection on the device it self might be available.
- Websockets and SSE are not supported.
- Requests and Responses are limited to 100KB in size
To include this library in your project, add the following dependency to your build.gradle
:
dependencies {
implementation "de.jonasfranz:ktor-client-karoo:1.0.1"
}
The library is released on the GitHub package repository. In order to add the repository you need to add this to your gradle buildscript:
dependencyResolutionManagement {
// ...
repositories {
maven {
url = uri("https://maven.pkg.github.com/jonasfranz/ktor-client-karoo")
credentials {
username = providers.gradleProperty("gpruser").getOrElse(System.getenv("USERNAME"))
password = providers.gradleProperty("gprkey").getOrElse(System.getenv("TOKEN"))
}
}
}
}
In order to use the repository authentication is required as described here.
Below is an example of how to use the Karoo Ktor Client:
val karooSystem: KarooSystemService = TODO()
val client = HttpClient(Karoo(karooSystem))
fun sendRequest() = runBlocking {
val response = client.get("https://api.sampleapis.com/wines/sparkling/${Random.nextInt(10)}")
print(response)
}
Please also have a look on the complete example in the app
directory.
This project is licensed under the Apache 2 License.