|
1 | | -# android-apifier |
2 | | -Library to abstract API and HTTP calls on android, backed by Cronet and OkHTTP |
| 1 | +# Android Apifier |
| 2 | + |
| 3 | +[](https://jitpack.io/#Androidacy/android-apifier) |
| 4 | +[](https://opensource.org/licenses/Apache-2.0) |
| 5 | + |
| 6 | +HTTP and API networking library for Android with Cronet and OkHttp. |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- **Cronet Integration**: Multi-provider Cronet support (GMS → Native → Java fallback) |
| 11 | +- **HTTP/3 & QUIC**: Modern protocol support for improved performance |
| 12 | +- **Configurable Retry**: Built-in exponential backoff and retry logic |
| 13 | +- **Progress Tracking**: Download/upload progress monitoring |
| 14 | +- **Secure Cookies**: Encrypted cookie storage with customizable backend |
| 15 | +- **Connection Optimization**: Mobile-optimized connection pooling and timeouts |
| 16 | +- **DSL Configuration**: Kotlin DSL for clean, type-safe configuration |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +Add JitPack repository: |
| 21 | + |
| 22 | +```gradle |
| 23 | +repositories { |
| 24 | + maven { url 'https://jitpack.io' } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +Add dependency: |
| 29 | + |
| 30 | +```gradle |
| 31 | +dependencies { |
| 32 | + implementation 'com.github.Androidacy:android-apifier:1.0.0' |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +## Documentation |
| 37 | + |
| 38 | +API documentation is available at [javadoc.jitpack.io](https://javadoc.jitpack.io/com/github/Androidacy/android-apifier/latest/javadoc/) |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +```kotlin |
| 43 | +val client = ApifierClient(context) { |
| 44 | + cronet { |
| 45 | + enableQuic = true |
| 46 | + enableHttp2 = true |
| 47 | + quicHint("api.example.com") |
| 48 | + cacheDirectory = context.cacheDir.resolve("cronet") |
| 49 | + } |
| 50 | + |
| 51 | + timeouts { |
| 52 | + connect = 5.seconds |
| 53 | + read = 60.seconds |
| 54 | + } |
| 55 | + |
| 56 | + retry { |
| 57 | + maxAttempts = 3 |
| 58 | + retryOn5xx = true |
| 59 | + } |
| 60 | + |
| 61 | + cookieStorage(MyCookieStorage()) |
| 62 | + header("User-Agent", "MyApp/1.0") |
| 63 | + dynamicHeader("Authorization") { getAuthToken() } |
| 64 | +} |
| 65 | + |
| 66 | +client.get("https://api.example.com/data", object : Callback { |
| 67 | + override fun onResponse(call: Call, response: Response) { |
| 68 | + // Handle response |
| 69 | + } |
| 70 | + |
| 71 | + override fun onFailure(call: Call, e: IOException) { |
| 72 | + // Handle error |
| 73 | + } |
| 74 | +}) |
| 75 | +``` |
| 76 | + |
| 77 | +## Cookie Storage |
| 78 | + |
| 79 | +Implement `CookieStorage` interface: |
| 80 | + |
| 81 | +```kotlin |
| 82 | +class MyCookieStorage : CookieStorage { |
| 83 | + override fun getStringSet(key: String, defaultValue: Set<String>?) = |
| 84 | + encryptedPrefs.getStringSet(key, defaultValue) |
| 85 | + |
| 86 | + override fun putStringSet(key: String, value: Set<String>) = |
| 87 | + encryptedPrefs.edit { putStringSet(key, value) } |
| 88 | + |
| 89 | + override fun remove(key: String) = |
| 90 | + encryptedPrefs.edit { remove(key) } |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## Progress Tracking |
| 95 | + |
| 96 | +```kotlin |
| 97 | +client.download(url, object : ProgressListener { |
| 98 | + override fun update(bytesRead: Long, contentLength: Long, done: Boolean) { |
| 99 | + val progress = (bytesRead * 100 / contentLength).toInt() |
| 100 | + updateProgressBar(progress) |
| 101 | + } |
| 102 | +}, callback) |
| 103 | +``` |
| 104 | + |
| 105 | +## Requirements |
| 106 | + |
| 107 | +- Android API 26+ |
| 108 | +- Kotlin 2.2+ |
| 109 | +- OkHttp 5.3+ |
| 110 | + |
| 111 | +## License |
| 112 | + |
| 113 | +``` |
| 114 | +Copyright 2025 Androidacy |
| 115 | +
|
| 116 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 117 | +you may not use this file except in compliance with the License. |
| 118 | +You may obtain a copy of the License at |
| 119 | +
|
| 120 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 121 | +
|
| 122 | +Unless required by applicable law or agreed to in writing, software |
| 123 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 124 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 125 | +See the License for the specific language governing permissions and |
| 126 | +limitations under the License. |
| 127 | +``` |
0 commit comments