5 releases
0.2.0 | Dec 28, 2022 |
---|---|
0.1.3 | Feb 16, 2022 |
0.1.2 | Feb 16, 2022 |
0.1.1 | Feb 15, 2022 |
0.1.0 | Feb 15, 2022 |
#23 in #cloudflare-workers
19KB
290 lines
Cloudflare Worker KV Proxy
This project is implemented to use Cloudflare KV in non-worker environment.
Setup KV and Proxy
- Copy whole content of
worker/kv_proxy.js
to create a new Cloudflare Worker using your browser, and clickSave and Deploy
. - Create a new KV namespace.
- Go to your worker(the worker you just created) settings, and:
- Add KV binding.
- 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
.
Dependencies
~4–20MB
~295K SLoC