1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! Impulse Server Kit
//!
//! State-of-art simple and powerful web server based on `salvo`. Provides extended tracing, configuration-over-YAML, HTTP/3, MessagePack support, ACME, OpenAPI and OpenTelemetry features by default, with one step to CORS and WebSockets.
//!
//! 4 Quick start steps:
//!
//! 1. Create `Setup` struct
//! 2. Create simple endpoints
//! 3. Create `server-example.yaml` file in crate root
//! 4. Just setup your application in 7 lines in `main`
//!
//! ```yaml
//! startup_type: http_localhost
//! server_port: 8801
//! allow_oapi_access: true
//! oapi_frontend_type: Scalar
//! oapi_name: Server Test OAPI
//! oapi_ver: 0.0.1
//! oapi_api_addr: /api
//! enable_io_logs: true
//! io_log_level: debug
//! ```
//!
//! ```rust,ignore
//! // Cargo.toml dependencies:
//! //
//! // impulse-server-kit = { git = "https://github.com/impulse-sw/impulse-kit.git", tag = "1.1.0" }
//! // serde = { version = "1", features = ["derive"] }
//! // tokio = { version = "1", features = ["macros"] }
//! // tracing = "1"
//!
//! use impulse_server_kit::prelude::*;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Deserialize, Default, Clone)]
//! struct Setup {
//! #[serde(flatten)]
//! generic_values: GenericValues,
//! // this could be your global variables, such as the database URLs
//! }
//!
//! impl GenericSetup for Setup {
//! fn generic_values(&self) -> &GenericValues { &self.generic_values }
//! fn generic_values_mut(&mut self) -> &mut GenericValues { &mut self.generic_values }
//! }
//!
//! #[derive(Deserialize, Serialize, Debug, salvo::oapi::ToSchema)]
//! /// Some hello
//! struct HelloData {
//! /// Hello's text
//! text: String,
//! }
//!
//! #[endpoint(
//! tags("test"),
//! request_body(content = HelloData, content_type = "application/json", description = "Some JSON hello to MsgPack"),
//! responses((status_code = 200, description = "Some MsgPack hello", body = HelloData, content_type = ["application/msgpack"]))
//! )]
//! #[instrument(skip_all, fields(http.uri = req.uri().path(), http.method = req.method().as_str()))]
//! async fn json_to_msgpack(req: &mut Request, depot: &mut Depot) -> MResult<MsgPack<HelloData>> {
//! let hello = req.parse_json::<HelloData>().await?;
//! let app_name = depot.obtain::<Setup>()?.generic_values().app_name.as_str();
//! msgpack!(HelloData { text: format!("From `{}` application: {}", app_name, hello.text) })
//! }
//!
//! #[endpoint(
//! tags("test"),
//! request_body(content = HelloData, content_type = "application/msgpack", description = "Some MsgPack hello to JSON"),
//! responses((status_code = 200, description = "Some JSON hello", body = HelloData, content_type = ["application/json"]))
//! )]
//! #[instrument(skip_all, fields(http.uri = req.uri().path(), http.method = req.method().as_str()))]
//! async fn msgpack_to_json(req: &mut Request, depot: &mut Depot) -> MResult<Json<HelloData>> {
//! let hello = req.parse_msgpack::<HelloData>().await?;
//! let app_name = depot.obtain::<Setup>()?.generic_values().app_name.as_str();
//! json!(HelloData { text: format!("From `{}` application: {}", app_name, hello.text) })
//! }
//!
//! fn tests_router() -> Router {
//! Router::new()
//! .push(Router::with_path("msgpack-to-json").post(msgpack_to_json))
//! .push(Router::with_path("json-to-msgpack").post(json_to_msgpack))
//! }
//!
//! #[tokio::main]
//! async fn main() {
//! let setup = load_generic_config::<Setup>("server-example").await.unwrap();
//! let state = load_generic_state(&setup, true).await.unwrap();
//! let router = get_root_router_autoinject(&state, setup.clone()).push(tests_router());
//! start(state, &setup, router).await.unwrap();
//! }
//! ```
//!
//! Here we go! You can now start the server with `cargo run --release`!
pub use salvo;
pub use tracing;
/// OpenTelemetry libraries' re-export.
pub use impulse_utils;