Kotlin. Make your first call.
Install the official Kotlin client and bring ParseAPI into your app.
Official Kotlin SDK
git clone --branch 1.8.0 --depth 1 https://github.com/parseapi/kotlin.git ../parseapi-kotlinYour language. The same ParseAPI.
Get connected
One country. Your first request.
Look up the United States and print its name.
Install the library.
Import your app module's BuildConfig when this file is in a different package. The app ID must match the key's allowed package name.
git clone --branch 1.8.0 --depth 1 https://github.com/parseapi/kotlin.git ../parseapi-kotlinincludeBuild("../parseapi-kotlin")dependencies {
implementation("com.parseapi:parseapi:1.8.0")
}Add your app key.
Create an app key in Keys and allow your application ID. Replace parse_app_... in the example.
Set appId to your application ID, as shown below. Carrier, HLR and Email mailbox verification require a secret key on your server.
Make a request.
Add this function to your app, then call it from a coroutine. This lookup uses your plan's request allowance.
import com.parseapi.ParseAPI
suspend fun loadCountry() {
val parse = ParseAPI("parse_app_...") {
appId = BuildConfig.APPLICATION_ID
}
val country = parse.country("US")
println(country.name)
}
// Call loadCountry() from your app's coroutine.United StatesHandle API errors
Read the error code and request ID when an API request fails. Branch on the code, such as not_found, rather than the message. A response with valid: false is a successful lookup. Transport failures still propagate.
import com.parseapi.ParseAPI
import com.parseapi.ParseAPIException
suspend fun loadCountry() {
val parse = ParseAPI("parse_app_...") {
appId = BuildConfig.APPLICATION_ID
}
try {
val country = parse.country("US")
println(country.name)
} catch (error: ParseAPIException) {
println("${error.code} ${error.status} ${error.requestId}")
throw error
}
}
// Call loadCountry() from your app's coroutine.Requests and retries
SDK methods follow the API routes. Unknown response values stay unknown, rather than becoming empty strings or guesses.
Ordinary lookups retry temporary failures. Separately metered checks make one attempt by default. You can configure the retry count. See the retry policy.