Lightweight HTTP requests library for Android.
kHttp Android is similar to Python's requests
module. This library has been adapted from kHttp by jkcclemens which is no longer maintained.
kHttp Android (pre-)releases are available via JitPack. It is recommended that a specific release version is selected when using the library in production as there may be breaking changes at anytime.
Tip: Test out the canary channel to try out features by using the latest develop snapshot;
develop-SNAPSHOT
.
// Project level build.gradle
// ...
repositories {
maven { url 'https://jitpack.io' }
}
// ...
// Module level build.gradle
dependencies {
// Replace version with release version, e.g. 1.0.0-alpha, -SNAPSHOT
implementation "io.karn:khttp-android:[VERSION]"
}
The most basic case is as follows:
// Get your IP synchronously
val ipAddress = get(url = "http://httpbin.org/ip").jsonObject.getString("origin")
// Get your IP asynchronously
get(url = "http://httpbin.org/ip")
.subscribe { response : Response ->
val ipAddress = response.jsonObject.getString("origin")
}
- There is an issue with parsing a list of maps into a JSONObject — a test case
doesJSONObjectBugExist
documents the issue within theKHttpPostTest.kt
file. This is platform related and cannot be fixed through this library. The current workaround is to build the JSONObject manually.
There are many ways to contribute, you can
- submit bugs,
- help track issues,
- review code changes.