The epsilon-networking module provides a robust, type-safe networking layer built on top of Ktor. It is designed to handle common networking tasks such as request execution, response deserialization, and structured error resolution.
This module is a common starting point when shared code needs a reusable HTTP client abstraction across platforms.
NetworkResponse<R> to represent success or failure.The main entry point for making network requests. It supports GET, POST, PUT, and DELETE methods.
Request example
val networking = Networking(
prioritizedErrorResolvers = listOf(MyNetworkErrorResolver()),
userAgent = "MyApp/1.0.0"
)
val response: NetworkResponse<User> = networking.get(Url("https://api.example.com/user/1"))A data class that represents the outcome of a network call. It contains either the successful data or an HttpError.
val response: NetworkResponse<User> = ...
if (response.isSuccess) {
val user = response.data // Depending on the type T, may be null even when isSuccess == true
} else {
val error = response.error // Will not be null if isSuccess == false
}You can use the unwrap method to handle both cases in a functional style:
unwrap is useful when you want to keep success and failure handling together in one expression.
val result = response.unwrap(
onSuccess = { data -> "Success: ${data.name}" },
onFailure = { error -> "Error: ${error.message}" }
)The NetworkErrorResolver interface allows you to define custom logic for parsing error bodies from failed requests.
Add the dependency to your commonMain:
dependencies {
implementation("ag.sportradar.mobile.epsilon:epsilon-networking:<version>")
}