cloudflare/endpoints/workers/
create_tail.rs

1use surf::http::Method;
2
3use super::WorkersTail;
4use crate::framework::endpoint::Endpoint;
5
6/// Create Tail
7/// https://api.cloudflare.com/#worker-create-tail
8#[derive(Debug)]
9pub struct CreateTail<'a> {
10    /// Account ID of owner of the script
11    pub account_identifier: &'a str,
12    /// The name of the script to tail
13    pub script_name: &'a str,
14    /// V1 of tailing involved creating a separate URL,
15    /// which is still possible.
16    ///
17    /// V2 does not involve a separate URL, so it can
18    /// be omitted.
19    pub params: CreateTailParams,
20}
21
22impl<'a> Endpoint<WorkersTail, (), CreateTailParams> for CreateTail<'a> {
23    fn method(&self) -> Method {
24        Method::Post
25    }
26    fn path(&self) -> String {
27        format!(
28            "accounts/{}/workers/scripts/{}/tails",
29            self.account_identifier, self.script_name
30        )
31    }
32    fn body(&self) -> Option<CreateTailParams> {
33        if self.params.url.is_some() {
34            Some(self.params.clone())
35        } else {
36            None
37        }
38    }
39}
40
41#[derive(Serialize, Clone, Debug, Default)]
42pub struct CreateTailParams {
43    /// URL to which to send events
44    pub url: Option<String>,
45}