Kwang is a thin Kotlin/Native wrapper around high-performance, low-overhead web server(s). It is in experimental state, supporting Lwan partially. It may have libh2o backend in the future.
git clone --recurse-submodules https://github.com/KwangIO/kwang
cd kwang
You can import it with IntelliJ IDEA
cmake
, zlib
, and libbsd
should be installed before building.
- Arch Linux:
pacman -S cmake zlib libbsd
- Ubuntu:
apt-get update && apt-get install git cmake zlib1g-dev pkg-config libbsd-dev
- I have not tried to build it on other operating systems
./buildLwan.sh
If you want more customization, see lwan#Building.
Open SampleLinux.kt
class SampleHandler : KwangHandler("/") {
override fun handleGet(request: RequestContext, response: ResponseContext): StatusCode {
println("Auth: ${request.authorization}")
println("Origin:" + request.getHeader("Origin"))
response withHeaders listOf(
Header("meaning-of-life", "42"),
Header("looking-for", "job")
) plain ("123")
return StatusCode(200u)
}
}
class OtherSample : KwangHandler("/hello") {
override fun handleGet(request: RequestContext, response: ResponseContext): StatusCode {
response json ("""{"hello":"${request.getQuery("name")}"}""")
return StatusCode(200u)
}
}
fun main(args: Array<String>) {
ServerLwan(listOf(SampleHandler(), OtherSample()), LwanConfig("localhost:8081"))
}
gradle runProgram
(no colorful output) or gradle build
(test will fail at the moment, just ignore it and run build/bin/linux/main/release/executable/kwang.kexe
)
The server will start on localhost:8081
The library is very EXPERIMENTAL and likely to change significantly, using it in production code is NOT RECOMMENDED. But yes, you can build the klib
(check gradle linuxKlibrary
)
Linux64
- Server configuration (
port
, ..) - CORS support (partially)
- Logging
- H2O backend (because Lwan does not support HTTP/2)
- Finish the wrapper
- Optimize performance
- EventBus
- WebSocket
- Path params / Full-featured router
TODO
In case you want benchmarking Kwang, you should consider compile lwan in release mode and pass -opt
to konanc
With autocannon -c 100 -d 40 -p 10 localhost:8080
, Kwang
reached around 80k reqs/sec on a MSI GE72VR laptop
Feel free to submit issues and enhancement requests. This is a low priority side-project to me, so there is no ETA/promise, but PRs are welcomed.
Agree.
I am not in the mood of choosing bike shed's name. Moreover, it is not that weird you racist people! Kwang in Korean
For current Kotlin/Native version (1.3.0
), it will not compile due to linker issue (please clone Kotlin/Native from github or wait for the next release)
(Kudos to Kotlin/Native team)
git clone https://github.com/JetBrains/kotlin-native --depth 1 -b master
cd kotlin-native
./gradlew dependencies:update
./gradlew bundle
cp -R dist/* ~/.konan/kotlin-native-linux-[ver]
or you can set konan.home
project property