Skip to main content

args_api/endpoint/metrics/
web_vital.rs

1use serde::{Deserialize, Serialize};
2
3use crate::endpoint::Endpoint;
4
5pub struct LogWebVital;
6
7impl Endpoint for LogWebVital {
8    const PATH: &'static str = "/metrics/web-vital";
9    const METHOD: http::Method = http::Method::POST;
10
11    type Request = LogWebVitalRequest;
12    type Response = ();
13}
14
15#[derive(ApiRequest, Debug, Serialize, Deserialize)]
16pub struct LogWebVitalRequest {
17    pub events: Vec<WebVitalEvent>,
18
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub country: Option<String>,
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub region: Option<String>,
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    pub city: Option<String>,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct WebVitalEvent {
29    pub event_time: i64,
30    pub name: String,
31    pub value: f64,
32    pub rating: String,
33    pub metric_id: String,
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub navigation_type: Option<String>,
36    pub route: String,
37    pub path: String,
38}