Hi again! I've implemented the ktor core client an...
# ktor
s
Hi again! I've implemented the ktor core client and works really nice with Android and iOS, but the idea is to reuse the common client also with JS, is there any way? Because looks like
Copy code
io.ktor:ktor-client-json
doesn't exists for JS, so I can't build the JS module, the dataSource is here -> https://github.com/sergiocasero/votlin-app/blob/feature/network_calls_common_client/common/src/main/kotlin/com/votlin/client/data/datasource/remote/CommonRemoteDataSource.kt
j
client can be used but looks like ktor-client-json-js dependency does not exist (yet?)
s
Yes yes, I've deleted that, right now I'm getting another issue regarding iOS haha
j
@e5l shall I open a ticket regarding the missing json feature on the JS side?
e
Sure
j
a ktor-client-json-js dependency, so we can use io.ktor.client.features.json.* classes
s
Yep, I've solved this with a WA on the common side
Copy code
class CommonRemoteDataSource : RemoteDataSource {

    private val endPoint: String = "<http://sergiocasero.es:10000>"

    private val client: HttpClient = HttpClient()

    override suspend fun getTalks(): List<Talk> =
            JSON.parse<TalksResponse>(client.get { apiUrl("talk") }).talks

    override suspend fun getTalk(talkId: Int): Talk =
            JSON.parse(client.get { apiUrl("talk/$talkId") })

    override suspend fun getTalksByTrack(track: String): List<Talk> =
            JSON.parse<TalksResponse>(client.get { apiUrl("talk/$track") }).talks

    override suspend fun rateTalk(rate: Rate): Unit = <http://client.post|client.post> {
        apiUrl("talk")
        body = JSON.stringify(rate)
    }

    private fun HttpRequestBuilder.apiUrl(path: String) {
        url {
            takeFrom(endPoint)
            encodedPath = path
        }
    }
}
(basically, using serializationx)