cloudflare/endpoints/workerskv/
list_namespace_keys.rs

1use super::Key;
2
3use crate::framework::endpoint::{serialize_query, EndpointSpec, Method};
4
5use crate::framework::response::ApiSuccess;
6use serde::Serialize;
7
8/// Lists a namespace's keys.
9///
10/// <https://developers.cloudflare.com/api/resources/kv/subresources/namespaces/subresources/keys/methods/list/>
11#[derive(Debug)]
12pub struct ListNamespaceKeys<'a> {
13    pub account_identifier: &'a str,
14    pub namespace_identifier: &'a str,
15    pub params: ListNamespaceKeysParams,
16}
17
18impl EndpointSpec for ListNamespaceKeys<'_> {
19    type JsonResponse = Vec<Key>;
20    type ResponseType = ApiSuccess<Self::JsonResponse>;
21
22    fn method(&self) -> Method {
23        Method::GET
24    }
25    fn path(&self) -> String {
26        format!(
27            "accounts/{}/storage/kv/namespaces/{}/keys",
28            self.account_identifier, self.namespace_identifier
29        )
30    }
31    #[inline]
32    fn query(&self) -> Option<String> {
33        serialize_query(&self.params)
34    }
35}
36
37#[serde_with::skip_serializing_none]
38#[derive(Serialize, Clone, Debug, Default)]
39pub struct ListNamespaceKeysParams {
40    pub limit: Option<u16>,
41    pub cursor: Option<String>,
42    pub prefix: Option<String>,
43}