Экспериментируя с Coroutines и Jetpack Compose и получая бесполезную трассировку стека от Retrofit:
java.lang.IllegalArgumentException: HTTP method annotation is required (e.g., @GET, @POST, etc.).
for method PokeApi.getPokeList
API вызова дооснащения (импортируются все 2.7.1):
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
interface PokeApi {
@GET("pokemon")
suspend fun getPokeList(@Query("limit") limit: Int = 151
): PokeListRequest
@GET("pokemon/{species}")
suspend fun getPokemon(@Path("species") pokemon: String
): PokeRequest
}
Сетевой абонент:
class PokeClient {
private var gson = Gson()
private var caller = Retrofit.Builder()
.baseUrl("https://pokeapi.co/api/v2/")
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
.create(PokeApi::class.java)
suspend fun getAllPokemon(): PokeListRequest {
return caller.getPokeList()
}
suspend fun lookupPokemon(species: String): PokeRequest {
return caller.getPokemon(species)
}
}
Вызов из ViewModel:
fun retrieveList() {
viewModelScope.launch {
PokeClient().getAllPokemon().results.map{it.name}
.also{pokeList.value = it}
}
}
}
Это не красиво, но я не понимаю, почему это не должно работать.