Reputation: 677
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) ?
Upvotes: 2
Views: 1409
Reputation: 21
There is a nice sample-app https://github.com/joreilly/PeopleInSpace . It uses common module with data for exposing to ktor-jvm-backend-service app. It can be a little slippery to explore since it's uses a lot of gradle stuff, but it's the price you have to pay for crossplatform projects
Also, you are welcome to explore my project: https://github.com/holdbetter/PremierLeague
I'm using shared module for my backend module in KMM project. It uses a little gradle magic too, but it's way more easier to explore. Be free to ask about it
There are some docs about building artifacts: https://kotlinlang.org/docs/multiplatform-dsl-reference.html#targets
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.
There are some facts about build artifacts
Upvotes: 1
Reputation: 1676
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.
Upvotes: 3