I want to use Retrofit's API but I want it to use ...
# android
a
I want to use Retrofit's API but I want it to use kotlin `Flow`s. I've searched around a little but found nothing particularly elegant. Currently my API returns a
Call<String>
. I'd like it to return a
Flow<String>
with the least amount of boilerplate possible. How are you all doing it?
j
can your api return more than one value? That would be the reason to have it return a flow. Otherwise make it a suspend function and just return the type
Copy code
@GET("/path")
suspend fun getSomething(): String
a
Simpler than I thought:
Copy code
interface ApiInterface {
  @GET("")
  suspend fun getThing():String
}

val scope = rememberCoroutineScope()
scope.launch {
  val thing:String = service.getThing()
}
1
Yeah I realised I didn't need a flow in the end.
Thanks
Maybe if I update the source, I'd like to get new items down, but I think that falls in the purview of channels
h
For changes from the server you would need a web socket.