Samkeene
01/09/2022, 10:45 PMfun Application.main() {
install(Compression)
routing {
applyRoutes(PingServiceManager)
get("/userlist") {
call.respondHtml(HttpStatusCode.OK) {
// send back my KVision UserPage class
}
}
}
kvisionInit()
}
I have the same file structure as the example (backendMain, commonMain, frontendMain). I'm simply unsure how to approach this.
Should I create an IUserListService
in commonMain
with a getUserListPage()
function, implement it in backendMain
and then call it from somewhere in frontendMain
? And add applyRoutes(UserListServiceManager)
to the ktor configuration? Assume I have a UserPage : SimplePanel()
class in the front end, also I see from the documentation that KVision Services' cannot return SimplePanel as a type... I'm not sure how I should be doing this...Robert Jaros
01/10/2022, 5:16 AMList<User>
(instead of UserPage
). When communicating with the backend keep your model clean and simple.
You shouldn't create routes manually on the ktor side. Instead just implement the service method and use applyRoutes(...)
. After that you will be able to just call the service method from your frontend and get your list of users. And only after the list is retrieved you create/modify the UI to display it (you can do this with both imperative and reactive code - the way you like - I personally prefer the reactive approach with the global state - stateflow or redux).Robert Jaros
01/10/2022, 5:31 AMSamkeene
01/10/2022, 4:53 PM