cloudflare_but_works/endpoints/workers/
create_tail.rs

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