https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

Nail Gilaziev

03/21/2018, 10:35 AM
Hello! Who knows, How to write a common module for jvm and js that make a http and json stuffs in it? do I need manually write HTTP and JSON parse classes via expect and actual for now?
👍 1
g

gildor

03/21/2018, 2:12 PM
Http stuff? Http client or server? Actually in both cases easiest way to use expect declaration and platform specific implementation. For Json you can use kotlinx.serialization #serialization
n

Nail Gilaziev

03/21/2018, 4:08 PM
Http client. For example web frontend and android jvm do same http requests and parse Json in a same way. Same business logic.
g

gildor

03/22/2018, 1:08 AM
I would just use expect/actual. Okhttp/retrofit for Android, Xmlhttprequest/fetch for js. Parsing is more interesting thing, maybe kotlinx.serialization
I mean in any case you need platform specific http client, for js you can use only particular API, there is no way to write http client from scratch. So such multiplatform library will use the same approach, common api that delegates work to platform specific apis and libraries But I agree, some standart common http client would be really helpful. #ktor already have some common parts for http client and server, you cannot use them now for multiplatform, but I think it will evolve to some separate multiplatform library
For json you can use the same approach, but I believe that for multiplatform kotlinx.serialization is much better, at least in the future
2 Views