タイトル通りです。
ぜ〜んぶ、Rubyから触れます!
プロジェクトの作成
$ cargo install uzumibi-cli@0.6.0-rc1
これで入るuzumibi cliでは、各種サービスを有効にしたCloudflareテンプレートを使える。 --features というフラグが用意されているので以下の感じ
$ uzumibi new -t cloudflare --features enable-external kv-test-1
あとはinstructionに従えばもう準備されてる状態に。デプロイもすぐできる。
Next steps:
0. Install required tools (if not installed):
• Rust & Cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
• Node.js tools:
npm install -g pnpm wrangler
• wasm-opt (Binaryen, required for asyncify):
brew install binaryen
Or visit: https://github.com/WebAssembly/binaryen/releases
1. Install dependencies:
pnpm install
2. Build and start development server:
pnpm run dev
3. Deploy to Cloudflare:
pnpm run deploy
(Queueだけは自分で作成して、wrangler.jsoncを更新してください mm)
Ruby側API
Uzumibi:: の配下に KV, Fetch, Queue が生えます。
class App < Uzumibi::Router get "/kv/set-test" do |req, res| Uzumibi::KV.set("test_key", "Hello from Uzumibi KV!") res.status_code = 200 res.headers = { "content-type" => "text/plain" } res.body = "Set test_key in KV store\n" res end get "/kv/get-test" do |req, res| value = Uzumibi::KV.get("test_key") || "Key not found" res.status_code = 200 res.headers = { "content-type" => "text/plain" } res.body = "Value of test_key: #{value}\n" res end get "/yesno" do |req, res| remote_res = Uzumibi::Fetch.fetch("https://yesno.wtf/api", "GET", "") debug_console("[Uzumibi] Fetched from yesno.wtf: #{remote_res.status_code}") debug_console("[Uzumibi] headers: #{remote_res.headers.inspect}") res.status_code = 200 res.headers = { "Content-Type" => "application/json", } res.body = remote_res.body res end get "/queue/send" do |req, res| Uzumibi::Queue.send("UZUMIBI_QUEUE", "Hello from Uzumibi Queue!") res.status_code = 200 res.headers = { "Content-Type" => "text/plain" } res.body = "Sent message to queue\n" res end end $APP = App.new
Queueはまだ送るだけです。受け取る時のインタフェース考え中。色々整ったらRC外す。
この調子で他のプラットフォームでもサービスも使えるようにしたい。で、なるべく種別でインタフェースを合わせたい気持ちがある。
取り急ぎはよく使うCloud Runで、 Firestore, Pub/Sub, (reqwest) 等を同じように使えるようにしたい。そんな感じで。