cloudflare-kv-proxy

Crates.iocloudflare-kv-proxy
lib.rscloudflare-kv-proxy
version0.2.0
sourcesrc
created_at2022-02-15 16:04:36.857529
updated_at2022-12-28 11:11:17.796948
descriptionCloudflare KV Proxy SDK.
homepage
repositoryhttps://github.com/ihciah/cloudflare-kv-proxy
max_upload_size
id532790
size60,635
ihc童鞋@提不起劲 (ihciah)

documentation

README

Cloudflare Worker KV Proxy

Crates.io MIT/Apache-2 licensed Build Status

This project is implemented to use Cloudflare KV in non-worker environment.

Setup KV and Proxy

  1. Copy whole content of worker/kv_proxy.js to create a new Cloudflare Worker using your browser, and click Save and Deploy.
  2. Create a new KV namespace.
  3. Go to your worker(the worker you just created) settings, and:
    1. Add KV binding.
    2. Add environment variable KEY, the value will be your access token(please make it long enough).

Usage

#[derive(Serialize, Deserialize, Debug)]
struct Demo {
    name: String,
    age: u8,
}
let data = Demo {
    name: "red".to_string(),
    age: 21,
};

let client = Client::new("https://your-proxy.workers.dev", "YOUR-TOKEN").unwrap();
println!("Put string: {:?}", client.put("test_key", "balabala").await);
println!("Get string: {:?}", client.get::<String>("test_key").await);

println!("Put struct: {:?}", client.put("test_key2", &data).await);
println!("Get struct: {:?}", client.get::<Demo>("test_key2").await);

Cache

To avoid unnecessary requests to Cloudflare, the proxy caches the response.

By default the caching is enabled. You can set default-features = false in Cargo.toml.

Commit count: 6

cargo fmt