cloudflare/endpoints/workerskv/
create_namespace.rs

1use super::WorkersKvNamespace;
2
3use surf::http::Method;
4
5use crate::framework::endpoint::Endpoint;
6
7/// Create a Namespace
8/// Creates a namespace under the given title.
9/// A 400 is returned if the account already owns a namespace with this title.
10/// A namespace must be explicitly deleted to be replaced.
11/// https://api.cloudflare.com/#workers-kv-namespace-create-a-namespace
12#[derive(Debug)]
13pub struct CreateNamespace<'a> {
14    pub account_identifier: &'a str,
15    pub params: CreateNamespaceParams,
16}
17
18impl<'a> Endpoint<WorkersKvNamespace, (), CreateNamespaceParams> for CreateNamespace<'a> {
19    fn method(&self) -> Method {
20        Method::Post
21    }
22    fn path(&self) -> String {
23        format!("accounts/{}/storage/kv/namespaces", self.account_identifier)
24    }
25    fn body(&self) -> Option<CreateNamespaceParams> {
26        Some(self.params.clone())
27    }
28}
29
30#[derive(Serialize, Clone, Debug)]
31pub struct CreateNamespaceParams {
32    pub title: String,
33}