![]() It'd be nice to have one global error handler for all http errors. This is great! Btw a good place to subscribe to a flowable is Presenter, if you are using MVP. Anyone can subscribe to choresFlowable, get items on subscription and also each time someone adds a new chore. This triggers GET chores http call, whose result is passed to all subscribers of choresFlowable. Once the response comes back from the server, choresChanged PublishProcessor emits a new empty ( Unit) item. What happens is that when addChore is invoked, POST chores http endpoint is called. To avoid nested Flowables, flattening is required ( flatmap = map + flatten) We do that by calling getChores endpoint, which also returns Flowable. var chores = listOf() //no need to provide type on left side of statementīackend.addChore(chore).enqueue(object : Callback - after choresChanged emits an empty item, we need to map it into chores. Using shiny, new interface it's possible to add chores and fetch them from a server. No equals, hashcode, constructors or toString. In Kotlin, DTOs can be defined as immutable data classes: data class ChoreId(val choreId: Long)ĭata class GetChoreDto(val id: Long,val name: String, val points: Int,val interval: Int?)ĭata class GetChoresDto(val chores: List)ĭata class AddChoreDto(val name: String, val points: Int, val interval: Int?) Using retrofit, we can define http endpoints in a type safe way: interface BackendService getChores() : addChoreDto: AddChoreDto) : Call The very first step was adding and getting chores from the server. ![]() The Process Consuming REST api with Retrofit I've used Retrofit before and had very positive experience with it.Īpart from that, it integrates nicely with RxJava. This is a type safe http client, handling all serialization and deserialization into user defined classes behind the scenes. It provides a way to chain and combine asynchronous flows of data. It usually leads to callback hell and complex state management. Traditionally it is done by listening to user input/IO and then changing state as a reaction to these events. We still need a way to glue these sources with the app. UI needs to be responsive at all times - that's why they need to be handled on a different threads. RxJava 2Īlmost every mobile app has at least two asynchronous sources of data - user input and IO (network/storage). Kotlin surprised me also with its great compile time (almost matching Java). It is already stable and has an excellent IDE support. Kotlin is JVM language which makes it compatible with existing Java libraries (RxJava and Retrofit being some of them).Īpart from that Kotlin is more functional than Java which helps to deal with the approach imposed by RxJava. ![]() The remaining decision was language and stack for it. I am a backend developer and my go-to language is Scala, so the choice for server side was quite clear.įor client side I decided to go with Android since doing house chores is highly mobile activity.Ĭonsidering nature of house chores, mobile client seemed like a good idea. The idea was to define a set of chores and assign them to users periodically.Įvery night, chores for the upcoming day are distributed to users (based on what they have done in the past). Recently I decided to create a pet project which would help me and my girlfriend split house chores.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |