What is the proper way to say, return a userlist p...
# kvision
What is the proper way to say, return a userlist page using ktor with Kvision? I've been following along the ktor example but am unsure of how to apply the route.
Copy code
fun Application.main() {
    routing {
        get("/userlist") {
            call.respondHtml(HttpStatusCode.OK) {
                // send back my KVision UserPage class
I have the same file structure as the example (backendMain, commonMain, frontendMain). I'm simply unsure how to approach this. Should I create an
with a
function, implement it in
and then call it from somewhere in
? And add
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...
Hi I would say your backend service should return just a
(instead of
). 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
. 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).
You should think of the KVision fullstack app like this: 1. The backend is all about business logic. You create services and methods that work with some data. E.g. store and retrieve data from externals sources (db, other web services), process the data (generating reports), authorize users and so on. You also create methods needed to get all the data necessary for your user interface (including methods directly bound with KVision fullstack components). 2. The frontend is the place you design your UI with KVision components. There are no strict rules - you can choose the way that best fits your application. The only thing you need to remember is that service methods are suspending and need to be called from the coroutines context. They are in fact asynchronous and for bigger applications you need to implement some reasonable architecture for your app.
Thanks Robert for the answer, you explained things very well and cleared so much up for me, much appreciated!