CepKMP

CepKMP is an asynchronous Kotlin Multiplatform library that retrieves address information based on a Brazilian postal code (CEP).
⚠️ This library currently supports only Brazilian postal codes.
🚀 Quick Start
First, add the dependency to your project:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.alderfurtado:cepkmp:$cepkmp_version")
}
Then, use the library in your code:
import com.cepkmp.cepkmp.api.AddressResponse
import com.cepkmp.cepkmp.CepKMP
suspend fun getAddress(postalCode: String): AddressResponse {
return CepKMP().getAddress(postalCode)
}
AddressResponse
The response will return either an Address object (on success) or a CepError (on failure).
Address Model
data class Address(
val zipCode: String,
val street: String,
val complement: String,
val unit: String,
val neighborhood: String,
val city: String,
val stateCode: String,
val state: String,
val region: String,
val ibgeCode: String,
val giaCode: String,
areaCode: String,
siafiCode: String
)
🧾 Address Fields Explained
CepError
CepError only extends a Exception Class
Usage Example
import com.cepkmp.cepkmp.CepKMP
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
fun fetchAddress(postalCode: String) {
CoroutineScope(Dispatchers.Main).launch {
{
address = withContext(Dispatchers.IO) {
CepKMP().getAddress(postalCode)
}
println()
} (e: Exception) {
println()
}
}
}
License
This project is licensed under the MIT License.