pub struct Server {
pub host: String,
pub protocol: String,
pub pathname: Option<String>,
pub description: Option<String>,
pub variables: Option<HashMap<String, ServerVariable>>,
}Expand description
Server connection information
Defines connection details for a server that hosts the API. Multiple servers can be defined to support different environments (production, staging, development).
§Example
use asyncapi_rust_models::{Server, ServerVariable};
use std::collections::HashMap;
let mut variables = HashMap::new();
variables.insert("userId".to_string(), ServerVariable {
description: Some("User ID for connection".to_string()),
default: None,
enum_values: None,
examples: Some(vec!["12".to_string(), "13".to_string()]),
});
let server = Server {
host: "chat.example.com:443".to_string(),
protocol: "wss".to_string(),
pathname: Some("/api/ws/{userId}".to_string()),
description: Some("Production WebSocket server".to_string()),
variables: Some(variables),
};Fields§
§host: StringServer URL or host
The hostname or URL where the server is hosted. May include port number. Examples: “localhost:8080”, “api.example.com”, “ws.example.com:443”
protocol: StringProtocol (e.g., “wss”, “ws”, “grpc”)
The protocol used to communicate with the server. Common values: “ws” (WebSocket), “wss” (WebSocket Secure), “grpc”, “mqtt”
pathname: Option<String>Optional pathname for the server URL
The pathname to append to the host. Can contain variables in curly braces (e.g., “/api/ws/{userId}”)
description: Option<String>Server description
An optional human-readable description of the server’s purpose or environment
variables: Option<HashMap<String, ServerVariable>>Server variables
A map of variable name to ServerVariable definition for variables used in the pathname