wasmer_deploy_schema/schema/
http_router.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use super::{entity::EntityDescriptorConst, WorkloadV2};
5
6#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
7pub struct HttpRouterSpecV1 {
8    /// List of domains this router should handle.
9    ///
10    /// May be empty if the domains are derived from another data source.
11    pub domains: Option<Vec<String>>,
12
13    /// Routes to handle.
14    pub routes: Vec<HttpRouteV1>,
15}
16
17impl EntityDescriptorConst for HttpRouterSpecV1 {
18    const NAMESPACE: &'static str = "wasmer.io";
19    const NAME: &'static str = "HttpRouter";
20    const VERSION: &'static str = "1alpha1";
21    const KIND: &'static str = "wasmer.io/HttpRouter.v1alpha1";
22    type Spec = Self;
23    type State = ();
24}
25
26/// An HTTP route of an HTTP router.
27#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
28pub struct HttpRouteV1 {
29    /// Optional name for this route.
30    /// Only used for debugging.
31    pub name: Option<String>,
32
33    /// Ordering priority.
34    ///
35    /// Will be used to disambiguate between overlapping routes.
36    pub priority: Option<i64>,
37
38    /// Matches that must be fulfilled for this route to be selected.
39    #[serde(default)]
40    pub matches: Vec<HttpRouteMatch>,
41
42    // TODO: add modifiers that can alter request and response.
43    // pub request_modifiers: Vec<serde_json::Value>,
44    // pub response_modifiers: Vec<serde_json::Value>,
45    /// The handler responsible for serving this route.
46    pub handler: HttpRouteHandlerV1,
47}
48
49#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
50pub enum HttpRouteHandlerV1 {
51    #[serde(rename = "spawn")]
52    Spawn(WorkloadV2),
53}
54
55#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
56pub struct HttpRouteMatch {
57    pub path: Option<HttpRoutePathMatch>,
58    pub methods: Option<Vec<String>>,
59    pub headers: Option<Vec<HttpRouteHeaderMatch>>,
60}
61
62#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
63pub enum HttpRoutePathMatch {
64    #[serde(rename = "prefix")]
65    Prefix(String),
66    #[serde(rename = "exact")]
67    Exact(String),
68    #[serde(rename = "regex")]
69    Regex(String),
70}
71
72#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
73pub struct HttpRouteHeaderMatch {
74    pub header: String,
75    pub value: HttpRouteHeaderValueMatch,
76}
77
78#[derive(Serialize, Deserialize, JsonSchema, PartialEq, Eq, Clone, Debug)]
79pub enum HttpRouteHeaderValueMatch {
80    #[serde(rename = "exact")]
81    Exact(String),
82    #[serde(rename = "regex")]
83    Regex(String),
84}
85
86pub type HttpRouterV1 = super::Entity<HttpRouterSpecV1>;