I am struggling with this issue hours a go I am trying to call the API using retrofit using this code
interface HTTPService {
@GET("/v1/breeds")
suspend fun getbreeds():BreedList
}
class Retrofitclass {
companion object{
val BaseURL = "https://docs.thedogapi.com"
fun getRetroInstance(): Retrofit {
val gson = GsonBuilder()
.setLenient()
.create()
return Retrofit.Builder()
.baseUrl(BaseURL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
}
}
}
In view Model:
fun makeApiCall(){
viewModelScope.launch(Dispatchers.IO){
// try {
val retroinstance = Retrofitclass.getRetroInstance().create(HTTPService::class.java)
val response = retroinstance.getbreeds()
print("responce"+ response )
selectdatalist.postValue(response)
// } catch (e: Exception) {
// print("error"+e.printStackTrace())
// }
}
}
Any help or suggestion I tried to add these codes in build.gradle but nothing works for me:
compile 'com.squareup.retrofit2:retrofit:2.0.0-SNAPSHOT'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'com.squareup.okhttp3:okhttp:3.0.1'