Android-Fx-Examples
Android-Fx-Examples copied to clipboard
Complete back to back example with Retrofit integration
It would be interesting to have an example that does not just fakes the web calls but also shows how to use the retrofit integration (https://arrow-kt.io/docs/0.10/integrations/retrofit/) and work with the results from the calls.
For people like me that are new to the whole way of thinking about effects in arrow.fx this would be really helpful to put some pieces together.
Somehow I missed this, sorry about that. This is the current state:
interface GithubService {
suspend fun getRepository(): RepositoryDto
}
to make it work with Retrofit you would annotate the method with @GET/@POST/@WHATEVER
and use Retrofit to create a service following the Retrofit docs. Since Retrofit already supports suspend functions, nothing changes in the usage code (ViewModel
layer). Only the construction of this object changes.
The integration with CallK
was done before Retrofit 2.6 (which started supporting suspend functions). You don't need that anymore.
Up next
The next Arrow release will include an integration that works with Kotlin's susped
system + Either. You can check the PR here: https://github.com/arrow-kt/arrow-integrations/pull/26 enabling you to declare your Retrofit service like:
interface SuspedApiClientTest {
@GET("/")
suspend fun getEither(): Either<ErrorMock, ResponseMock>
}
that way you get your 4XX-5XX errors as Either.Left
and successful responses as Either.Right
.
Does this answer your question?