
HTTP client wrapper simplifying API requests with flexible manual JSON navigation and automatic serialization-based decoding, handling messy or deeply nested API responses with configurable request helpers.
This library is a wrapper on top of Ktor-Client and FluidJson to facilitate both manual and automatic deserialization when working with APIs that are not well formatted. Works on Android 5.0+ (API level 21+) and Java 8+.
Take for example the following JSON response:
{
"data": {
"user": {
"info": {
"name": "John",
"email": "john@example.com"
}
}
}
}val apiClient = ApiClient(baseUrl = "https://example.com/")
launch {
val user = apiClient.get(
endpoint = "user"
) { json ->
User(
name = json["data"]["user"]["info"]["name"].string,
email = json["data"]["user"]["info"]["email"].string
)
}
user.name
}val apiClient = ApiClient(baseUrl = "https://example.com/")
launch {
val user = apiClient.put(
endpoint = "user",
body = jsonObjectBody {
obj["name"] = "Doe"
}
) { json ->
User(
name = json["data"]["name"].string, //in this case the response has another format
email = json["data"]["email"].string
)
}
}Don't forget to apply the Kotlin Serialization plugin
@Serializable
data class ResponseWrapper<T>(
val data: T
)
@Serializable
data class UserWrapper(
val user: UserInfo
)
@Serializable
data class UserInfo(
val info: User
)
@Serializable
data class User(
val name: String,
val email: String
)
val apiClient = ApiClient(baseUrl = "https://example.com/")
launch {
val userResponse = apiClient.get(
endpoint = "user"
) { json ->
json.decode<ResponseWrapper<UserWrapper>>()
}
userResponse.data.user.info.name
}The latest release is available on Maven Central.
implementation("net.mready.apiclient:core:1.1.1")Copyright 2025 mReady Solutions SRL.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This library is a wrapper on top of Ktor-Client and FluidJson to facilitate both manual and automatic deserialization when working with APIs that are not well formatted. Works on Android 5.0+ (API level 21+) and Java 8+.
Take for example the following JSON response:
{
"data": {
"user": {
"info": {
"name": "John",
"email": "john@example.com"
}
}
}
}val apiClient = ApiClient(baseUrl = "https://example.com/")
launch {
val user = apiClient.get(
endpoint = "user"
) { json ->
User(
name = json["data"]["user"]["info"]["name"].string,
email = json["data"]["user"]["info"]["email"].string
)
}
user.name
}val apiClient = ApiClient(baseUrl = "https://example.com/")
launch {
val user = apiClient.put(
endpoint = "user",
body = jsonObjectBody {
obj["name"] = "Doe"
}
) { json ->
User(
name = json["data"]["name"].string, //in this case the response has another format
email = json["data"]["email"].string
)
}
}Don't forget to apply the Kotlin Serialization plugin
@Serializable
data class ResponseWrapper<T>(
val data: T
)
@Serializable
data class UserWrapper(
val user: UserInfo
)
@Serializable
data class UserInfo(
val info: User
)
@Serializable
data class User(
val name: String,
val email: String
)
val apiClient = ApiClient(baseUrl = "https://example.com/")
launch {
val userResponse = apiClient.get(
endpoint = "user"
) { json ->
json.decode<ResponseWrapper<UserWrapper>>()
}
userResponse.data.user.info.name
}The latest release is available on Maven Central.
implementation("net.mready.apiclient:core:1.1.1")Copyright 2025 mReady Solutions SRL.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.