cloudflare/endpoints/workerskv/
write_bulk.rs

1use surf::http::Method;
2
3use crate::framework::endpoint::Endpoint;
4
5/// Write Key-Value Pairs in Bulk
6/// Writes multiple key-value pairs to Workers KV at once.
7/// A 404 is returned if a write action is for a namespace ID the account doesn't have.
8/// https://api.cloudflare.com/#workers-kv-namespace-write-multiple-key-value-pairs
9#[derive(Debug)]
10pub struct WriteBulk<'a> {
11    pub account_identifier: &'a str,
12    pub namespace_identifier: &'a str,
13    pub bulk_key_value_pairs: Vec<KeyValuePair>,
14}
15
16impl<'a> Endpoint<(), (), Vec<KeyValuePair>> for WriteBulk<'a> {
17    fn method(&self) -> Method {
18        Method::Put
19    }
20    fn path(&self) -> String {
21        format!(
22            "accounts/{}/storage/kv/namespaces/{}/bulk",
23            self.account_identifier, self.namespace_identifier
24        )
25    }
26    fn body(&self) -> Option<Vec<KeyValuePair>> {
27        Some(self.bulk_key_value_pairs.clone())
28    }
29    // default content-type is already application/json
30}
31
32#[serde_with::skip_serializing_none]
33#[derive(Serialize, Deserialize, Clone, Debug)]
34pub struct KeyValuePair {
35    pub key: String,
36    pub value: String,
37    pub expiration: Option<i64>,
38    pub expiration_ttl: Option<i64>,
39    pub base64: Option<bool>,
40}