Kine (Kotlin I/O Networking Extensions)
A simple and powerful HTTP networking library for Kotlin/Android.
Features
- [x] Supports HTTP GET/POST/PUT/DELETE/HEAD/PATCH
- [x] Supports synchronous and asynchronous requests
- [x] Download file with progress
- [x] Get Image as bitmap from url
- [x] MultiPart Upload
- [x] Response caching in disk
- [x] OkHttp cache control full support
- [x] Supports OkHttp with ability to write your own Httpclient
- [x] Cancel any in-flight request
- [x] Request timeout with retry policy
- [x] App Wide Configuration using
Kime
with support for common Headers , base Url for all request - [x] Log manager with option to turn logging off for per request and App wide
- [x] Supports response deserialization into POJO/POKO with Gson or Moshi
- [x] Supports reactive programming via RxJava 2.x / RxJava 3.x
- [x] Supports kotlin coroutines
- [x] Supports live data
- [x] Supports ability to handle any type of response with custom converter option
Upcoming Planned Features
- Support for jackson parser
- Bitmap caching and auto previous request cancellation for ImageLoading
- New interceptor api for manipulating request pre execute
Installation
Library is available on jcenter
Gradle
Note: Kine will autodetect if android,okhttp,gson or moshi dependency are there and set appropriate client, converter or main thread callback you don't need to specify them,if both moshi and gson are there, kine will add moshi first(converter are always called by add order so if you have both dependency and trying to parse it using gson it won't work). To override this behaviour you can set them using Kine.builder()
as shown below
Usage
Kine Configuration
Note: Options provided with individual KineRequest
will always take priority over Kine
global configuration except for headers , headers will always be added to individual request headers specified by the user
Kine requests can be made with KineRequest
class or using one of the String
or other extension methods.
If you specify a callback the call is asynchronous, if you don't its synchronous.
Exception will be thrown in synchronous (you need to catch them).
Exception will be delivered to onError callback in asynchronous except for user error like not specifying a converter and expecting a parsed response.
Get Json
Get String
Get JsonArray
Gson (requires kine-gson dependency) / Moshi (requires kine-moshi dependency)
RxJava2 (requires kine-rxjava2 dependency) / RxJava3 (requires kine-rxjava3 dependency)
Single
Flowable
Observable
Kotlin Coroutine (requires kine-coroutine dependency)
Download File
Image Loading (requires kine-imageloader dependency)
Load Bitmap From Url
Load Image from Url to ImageView
Cancelling request
Application
Individual Request
MultiPart Image Upload
Requirements
For Android
OkHttp 4x
- Min SDK 21+(for OkHttpClient you can write your own client for supporting Api Version below it)
- Java 8+
OkHttp 3x (legacy)
- Min SDK 9+(for OkHttpClient you can write your own client for supporting Api Version below it)
- Java 7+
For Kotlin/Java
- Kotlin 1.4/Java 8+