https://kotlinlang.org logo
Title
i

Ian

07/27/2020, 7:31 PM
Hi @pabl0rg.  I'm not too familiar with HTTP4k but it should be possible, although it would require abstracting out the HTTP/WebSocket transport code, which isn't something I'd contemplated previously. Does HTTP4k have significant advantages over Ktor, or is it more that you're locked into it?
p

pabl0rg

07/27/2020, 7:34 PM
The nice thing about http4k is it's all just functions. For that reason, it should be easy to switch to ktor, with the main disadvantage being losing easy testability. I'll give it a try, though. Thanks!
The advantage of somehow refactoring kweb into function/functions that could be connected to different http frameworks is that people could add it in to whatever weird setup they've got. I wonder if @dave knows about kweb?
i

Ian

07/27/2020, 7:41 PM
That would be good - I don't think I've spoken to @dave so not sure if he is familiar with Kweb. Kweb uses Ktor for HTTP/HTTPS transport and WebSocket transport. It would be great if that could be abstracted out, provided that it didn't complicate Kweb's simpler use-cases.
p

pabl0rg

07/27/2020, 7:43 PM
yeah, it might help adoption if people can try making a screen or two with it in an existing project.
👍 1
i

Ian

07/27/2020, 7:45 PM
The Ktor integration is mostly contained within the
Kweb
class: https://github.com/kwebio/kweb-core/blob/master/src/main/kotlin/kweb/Kweb.kt
d

dave

07/28/2020, 6:45 AM
yeah - we do know about kweb, but haven't really used it TBH. But all the bits seem to be there to make it workable into an http4k integration. you would be locked into Jetty because that's the only http4k engine that supports websockets at the moment. All of the current KWeb code would need to be ported into creating a
PolyHandler
which could then be converted using
asServer(Jetty(...))
. However, for partially applying it to individual pages as per @pabl0rg’s idea you would need to do something funky with the routing to mix in the kweb routes with the standard http4k ones. PBasically you'd need to migrate all of the w/s stuff from Kweb.kt into an http4k and then you could mix in
👍 1
Looks like that KWeb.kt file contains a mix of Ktor and KWeb logic, so that could be a place to start teasing it apart. 🙂
👍 1