Skip to content

Instantly share code, notes, and snippets.

@hissain
Created April 1, 2020 22:34
Show Gist options
  • Save hissain/d30c189bc602bf4609c70863db2c0e4d to your computer and use it in GitHub Desktop.
Save hissain/d30c189bc602bf4609c70863db2c0e4d to your computer and use it in GitHub Desktop.
Rest Api Service Class
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
class RestApiService {
fun addUser(userData: UserInfo, onResult: (UserInfo?) -> Unit){
val retrofit = ServiceBuilder.buildService(RestApi::class.java)
retrofit.addUser(userData).enqueue(
object : Callback<UserInfo> {
override fun onFailure(call: Call<UserInfo>, t: Throwable) {
onResult(null)
}
override fun onResponse( call: Call<UserInfo>, response: Response<UserInfo>) {
val addedUser = response.body()
onResult(addedUser)
}
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment