Skip to content

SupunIsharaWK/AndroidRestClientKot24

Repository files navigation

RestClientKot24 – A Kotlin AAR Library for REST API Communication

RestClientKot24 is a modern, extensible, and testable REST client library built in Kotlin using OkHttp. It wraps complex HTTP handling into a fluent, configurable API designed for Android and JVM-based apps.

πŸ”– Version 1.0.2 – Initial public release published via GitHub Packages.


πŸš€ Features

  • βœ… Fluent Request object builder
  • βœ… Supports GET, POST, PUT, PATCH, DELETE
  • βœ… Configurable headers, body (JSON, form, multipart, etc.)
  • βœ… Built-in coroutine support (suspend fun executeRequestSuspend())
  • βœ… Multiple callback support:
    • MultiResponseCallback (success, failure, retry, cache)
    • ProgressCallbacks (start/end)
  • βœ… Persistent caching using SQLite via CacheManager
  • βœ… Support for Gzip decoding
  • βœ… Request debugging: log headers, payloads, response
  • βœ… SSL & HostnameVerifier injection
  • βœ… Optional in-memory cookie jar support
  • βœ… Full unit test suite with JUnit 4, MockK, and AndroidX

πŸ“¦ Installation

You can integrate RestClientKot24 using GitHub Packages.

Step 1: Add GitHub Maven repository

In your project-level settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://maven.pkg.github.com/SupunIsharaWK/AndroidRestClientKot24")
            credentials {
                username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
                password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
            }
        }
    }
}

Step 2: Add dependency

In your app-level build.gradle.kts:

dependencies {
    implementation("com.github.SupunIsharaWK:restclientkot24:1.0.2")
}

πŸ’‘ Don’t forget to define gpr.user and gpr.key in your ~/.gradle/gradle.properties.

πŸ”§ Basic Usage

val request = Request.fromUrl("https://api.example.com", Request.Method.POST).apply {
  setBody(JSONObject().put("name", "TestBody"))
  addHeader(Header("Authorization", "Bearer token"))
  enableResponseCaching(60000)
}

val restClient = RestClient(context)
restClient.setConfig(ConfigBuilder().debugPrintInfo().build())

restClient.executeRequest(request,
  multiCallback = object : MultiResponseCallback() {
    override fun onSuccess(response: Response) {
      Log.d("API", response.responseBody)
    }
    override fun onFailure(exception: Throwable) {
      Log.e("API", "Failed", exception)
    }
  }
)

πŸ§ͺ Unit Testing

The project includes comprehensive unit tests for:

  • RestClient
  • Request
  • Response
  • Header, CacheData
  • RestClientException, ConnectionException
  • CacheManager with DatabaseHelper

Run tests using:

./gradlew test

πŸ“‚ Project Structure

πŸ“¦ restclientkot24/
β”œβ”€β”€ java/com/supunishara/restclientkot24/
β”‚   β”œβ”€β”€ RestClient.kt
β”‚   β”œβ”€β”€ Request.kt
β”‚   β”œβ”€β”€ Response.kt
β”‚   β”œβ”€β”€ cache/
β”‚   β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ callbacks/
β”‚   β”œβ”€β”€ exceptions/
β”‚   β”œβ”€β”€ data_classes/
β”‚   └── helpers/
β”œβ”€β”€ test/                # Unit tests
β”œβ”€β”€ androidTest/         # Instrumented tests

πŸ›‘πŸ›‘οΈ License

MIT License. Feel free to fork and contribute.


🀝 Contributing

Pull requests are welcome! Please write unit tests for any new features and ensure all existing tests pass.


πŸ‘€ Author

Supun Weerasekara πŸ“§ Email: supun266@gmail.com πŸ”— GitHub: SupunIsharaWK

About

πŸ“¦ RestClientKot24 – Lightweight Kotlin AAR for REST API Communication

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •  

Languages