cloudflare/endpoints/workers/
create_route.rs

1use surf::http::Method;
2
3use super::WorkersRouteIdOnly;
4use crate::framework::endpoint::Endpoint;
5
6/// Create a Route
7/// Creates a route mapping the given pattern to the given script
8/// https://api.cloudflare.com/#worker-routes-create-route
9#[derive(Debug)]
10pub struct CreateRoute<'a> {
11    pub zone_identifier: &'a str,
12    pub params: CreateRouteParams,
13}
14
15impl<'a> Endpoint<WorkersRouteIdOnly, (), CreateRouteParams> for CreateRoute<'a> {
16    fn method(&self) -> Method {
17        Method::Post
18    }
19    fn path(&self) -> String {
20        format!("zones/{}/workers/routes", self.zone_identifier)
21    }
22    fn body(&self) -> Option<CreateRouteParams> {
23        Some(self.params.clone())
24    }
25}
26
27/// pattern: the zone name along with glob-style wildcards
28///         e.g. "example.net/*"
29/// script: Name of the script to apply when the route is matched.
30///         The route is skipped when this is blank/missing.
31#[derive(Serialize, Clone, Debug)]
32pub struct CreateRouteParams {
33    pub pattern: String,
34    pub script: Option<String>,
35}