Android-Fx-Examples icon indicating copy to clipboard operation
Android-Fx-Examples copied to clipboard

Complete back to back example with Retrofit integration

Open jleidgens opened this issue 4 years ago • 1 comments

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.

jleidgens avatar Jun 10 '20 15:06 jleidgens

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?

LordRaydenMK avatar Jun 22 '20 19:06 LordRaydenMK