2

GitHub - kwebio/kweb-core: A web framework for Kotlin developers

 1 year ago
source link: https://github.com/kwebio/kweb-core
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Kweb - The Kotlin web framework for backend developers

Quick Start

Read the Introduction or Getting Started from the Kweb User Manual.

Why another web framework?

Modern websites consist of at least two tightly coupled components, one runs in the browser, the other on the server. These are often written in different programming languages and must communicate with each other over an HTTP(S) connection.

Kweb's goal is to eliminate this server/browser separation so you can focus on building your website or user interface, not on the plumbing.

What is Kweb?

Kweb is a remote interface to the web browser's DOM, driven by the server. With Kweb, you can create and manipulate DOM elements, and even bind values in your realtime database to DOM elements so they update automatically when the database changes.

Kweb is built on the Ktor framework, which handles HTTP, HTTPS, and WebSocket transport. You don't need to know Ktor to use Kweb, but if you already have a Ktor app, you can embed Kweb as a feature.

A common concern about server-driven interfaces is that they can feel sluggish. Kweb solves this problem by preloading instructions to the browser so that they are executed immediately on browser events, without the need for a round-trip to the server.

Example

import kweb.*
import kweb.InputType.text


fun main() {
    Kweb(port = 16097) {
        doc.body {
            val name = kvar("")
            div {
                h1().text("Enter Your Name")
                input(type = text).value = name
            }
            div {
                span().text(name.map { "Hello, $it" })
            }
        }
    }
}

Result

This example illustrates creating DOM elements, modifying elements, KVars, and binding input elements.

197428328-9a42d5e2-f6c9-43f8-9d7c-62fe1a445dab.gif

Learn More


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK