The main idea is to have a sort of "serialization / deserialization module" that could be shared between a backend (using Ktor) and an Android application.
I don't know how "far" this can go, but I would imagine that the routes are "exposed" for the frontend app to consume (like Retrofit does with its interface with annotations) and the (de-)serialization logic is shared too.
So basicaly, is it possible to "share" not only the "POJO / POKO" representations of API responses, but also the possible endpoints with the expected parameters, between a server (I guess using Ktor) and an Android application (Java / Kotlin)?
Yes.
You can structure your code with a multi project gradle build like this:
This is a little bit like the Dependency Inversion Principal
from SOLID. You define the interface of the data exchange in a seperate module(API module). And then, both the implementation (Server Module) and the higher level code (Android Module) depend on that for its use and implementation.
I had tried to run something like this, it didn't work in my way
It's impossible to share data between Ktor and Android in Kotlin Multiplatform paradigm. Let's figure it out:
Multiplatform and Multiplatform are friends. So who is not - eliminated
Since multiplatform library builds into parts one of them should be.jar and you can share it for Android project and Ktor project. I don't know where you can find them, but i think it's possible.
In my case it's not appropriate because it's not cross-platform way. You can't have iOS, macOS in this scenario. And you have to build and store your.jar separately.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.