use super::WorkersRouteIdOnly;
use crate::framework::endpoint::{EndpointSpec, Method, RequestBody};
use crate::framework::response::ApiSuccess;
use serde::Serialize;
#[derive(Debug)]
pub struct CreateRoute<'a> {
pub zone_identifier: &'a str,
pub params: CreateRouteParams,
}
impl EndpointSpec for CreateRoute<'_> {
type JsonResponse = WorkersRouteIdOnly;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::POST
}
fn path(&self) -> String {
format!("zones/{}/workers/routes", self.zone_identifier)
}
#[inline]
fn body(&self) -> Option<RequestBody> {
let body = serde_json::to_string(&self.params).unwrap();
Some(RequestBody::Json(body))
}
}
#[derive(Serialize, Clone, Debug)]
pub struct CreateRouteParams {
pub pattern: String,
pub script: Option<String>,
}