salvo-websocket
Salvo WebSocket
WebSocketUpgrade from salvo-extra turns a GET handler into a WebSocket endpoint. WebSocket implements Stream<Item = Result<Message, Error>> + Sink<Message, Error = Error>, so StreamExt::split(), recv(), and send() all work.
Setup
[dependencies]
salvo = { version = "0.89.3", features = ["websocket"] }
futures-util = "0.3"
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
Echo server
use salvo::prelude::*;
use salvo::websocket::WebSocketUpgrade;
More from salvo-rs/salvo-skills
salvo-cors
Configure Cross-Origin Resource Sharing (CORS) and security headers. Use for APIs accessed from browsers on different domains.
16salvo-database
Integrate databases with Salvo using SQLx, Diesel, SeaORM, or other ORMs. Use for persistent data storage and database operations.
16salvo-middleware
Implement middleware for authentication, logging, CORS, and request processing. Use for cross-cutting concerns and request/response modification.
16salvo-caching
Implement caching strategies for improved performance. Use for reducing database load and speeding up responses.
16salvo-timeout
Configure request timeouts to prevent slow requests from blocking resources. Use for protecting APIs from long-running operations.
16salvo-error-handling
Handle errors gracefully with custom error types, status codes, and error pages. Use for building robust APIs with proper error responses.
15