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
James Harman
09/02/2021, 12:17 AM
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
adjpd
09/02/2021, 12:17 AM
Simpler than I thought:
Copy code
interface ApiInterface {
@GET("")
suspend fun getThing():String
}
val scope = rememberCoroutineScope()
scope.launch {
val thing:String = service.getThing()
}
✅ 1
adjpd
09/02/2021, 12:18 AM
Yeah I realised I didn't need a flow in the end.
adjpd
09/02/2021, 12:18 AM
Thanks
adjpd
09/02/2021, 12:18 AM
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
hfhbd
09/02/2021, 8:56 AM
For changes from the server you would need a web socket.