Skip to content

Kotlin HTTP request library for Android, adapted from @jkcclemens/khttp.

License

Notifications You must be signed in to change notification settings

Karn/khttp-android

Repository files navigation

kHttp

kHttp Android

Lightweight HTTP requests library for Android.

Kotlin RxJava Build Status Codecov GitHub (pre-)release

kHttp Android is similar to Python's requests module. This library has been adapted from kHttp by jkcclemens which is no longer maintained.

GETTING STARTED

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]"
}

USAGE

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")
    }

KNOWN ISSUES

  • There is an issue with parsing a list of maps into a JSONObject — a test case doesJSONObjectBugExist documents the issue within the KHttpPostTest.kt file. This is platform related and cannot be fixed through this library. The current workaround is to build the JSONObject manually.

CONTRIBUTING

There are many ways to contribute, you can

  • submit bugs,
  • help track issues,
  • review code changes.