Scala example of Workers KV
APACHE-2.0 License
Main.scala is an example of using Cloudflare Workers KV from Scala.
In addition to Wrangler you will need to install the Scala build tool sbt, including a JDK.
To generate using wrangler
wrangler generate projectname https://github.com/cloudflare/scala-worker-kv
When editing wrangler.toml to include your account_id, you will also need to add your kv namespace id to the binding under kv-namespaces.
Further documentation for Wrangler can be found here.
After installing sbt per the linked instructions above,
cd projectname
sbt fullOptJS
That will compile your code and package it into index.js, after which you can run wrangler publish
to push it to Cloudflare.
If you just want to check for errors during development without taking the time to package, running sbt ~compile
will watch for filesystem changes and recompile. For more information, see the sbt docs
For more information on how Scala translates to Javascript, see the Scala.js docs.