cloudflare/endpoints/workerskv/
read_key.rs

1use crate::framework::endpoint::EndpointSpec;
2use crate::framework::endpoint::Method;
3use crate::framework::response::ApiResult;
4
5/// Returns the value associated with the given key in the given namespace.
6///
7/// Use URL-encoding to use special characters (for example, `:`, `!`, `%`) in the key name.
8/// If the KV-pair is set to expire at some point, the expiration time as measured in seconds since
9/// the UNIX epoch will be returned in the expiration response header.
10///
11/// <https://developers.cloudflare.com/api/resources/kv/subresources/namespaces/subresources/values/methods/get/>
12#[derive(Debug)]
13pub struct ReadKey<'a> {
14    pub account_identifier: &'a str,
15    pub namespace_identifier: &'a str,
16    pub key: &'a str,
17}
18
19impl ApiResult for Vec<u8> {}
20
21impl EndpointSpec for ReadKey<'_> {
22    const IS_RAW_BODY: bool = true;
23
24    type JsonResponse = ();
25    type ResponseType = Vec<u8>;
26
27    fn method(&self) -> Method {
28        Method::GET
29    }
30    fn path(&self) -> String {
31        format!(
32            "accounts/{}/storage/kv/namespaces/{}/values/{}",
33            self.account_identifier,
34            self.namespace_identifier,
35            super::url_encode_key(self.key)
36        )
37    }
38}