github varabyte/kobweb v0.13.9

latest releases: v0.24.0, v0.23.3, v0.23.2...
2 years ago

🌊💦 In this release, API streams make a splash 🚣‍♀️

Previously, Kobweb only supported API routes, for client-driven request-then-response operations.

Starting now, API streams allow persistent connections between Kobweb clients and servers, where, once connected, either side can send messages to the other as often as they want.

API streams are great for real-time communication, especially when you want the server to drive behavior on the client without the need for constant polling.

Here is the minimal code needed to set up an echo service (where the server just returns any message sent from the client back at them):

// Backend
val echo = ApiStream { ctx -> ctx.stream.send(ctx.text) }

// Frontend
val echoStream = rememberApiStream("echo") { ctx -> console.log("Echoed: ${ctx.text}") }

// later:
echoStream.send("Hello!")

What can you do with API streams? It can be well suited for applications like chat rooms and multiplayer games.

One of Kobweb's power users, @DennisTsar, put together this incredible chess demo, featuring both gameplay and spectating features:

msedge_oPCpMnHETw.mp4

API streams open up the door to a lot of fun ideas, and we look forward to seeing what creative projects people in the community come up with.


Frontend / Backend

  • You can create API streams now. You can learn more about this feature in the README.
    • The examples/chat example was updated to use API streams, if you want to check out a semi-realistic example.

Markdown

  • You can now instruct Kobweb markdown to create imports in the generated code.
    • This can significantly simplify calling code inside Kobweb markdown files.
    • You can specify global imports inside your build script that will get added to all generated files, or local imports inside your markdown front matter directly that only apply to the single file they generate.
    • You can learn more about this feature in the README.
    • Thank you @dead8309 for filing and describing this issue!

Full Changelog: v0.13.8...v0.13.9

Don't miss a new kobweb release

NewReleases is sending notifications on new releases.