https://kotlinlang.org logo
Title
j

Jakub

11/02/2018, 10:41 AM
Cool, how do you organize these functions @karelpeeters? Are they functions kept in data classes, extensions or they are separated Translators or something?
k

karelpeeters

11/02/2018, 10:48 AM
Disclaimer: I haven't worked on a big project that had rest api stuff as the main feature, but this worked for me. The API started with an
Account
class that had a function to send requests with the appropriate sessions id etc, it had a parameter for extra parameters on the request. Then on Account there were functions that returned some data about it, eg
Account.contacts(): List<Contact>
. Those Contact objects looked somewhat like this:
data class Contact(val account: Account, val name: String) {
    fun details(): ContactDetails {
        return parse<ContactDetails>(account.sendRequest("contact/$name"))
    }
}
And then
ContactDetails
kept a reference to the
Contact
object as well, something like:
data class ContactDetails(val contact: Contact, val name: String, val age: Int)
👍 1
j

Jakub

11/02/2018, 11:14 AM
Thank you!