axum-impl-websockets

Implement Axum WebSocket endpoints with upgrade handling and concurrent messaging.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-websockets
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-impl-websockets
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-impl/axum-impl-websockets
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-websockets

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents common, production-impacting WebSocket implementation mistakes in Axum—especially around concurrency, upgrade failures, and Axum 0.7 to 0.8 Message type changes.

Core Features & Use Cases

  • Correct WebSocket upgrade wiring: Use WebSocketUpgrade, on_upgrade, and optional on_failed_upgrade so upgrades succeed and failures are visible.
  • Right concurrency model: Avoid the sequential-only echo trap by using socket.split(), tokio::spawn, and tokio::select! for true concurrent send/receive.
  • Version-aware Message handling (0.7 → 0.8): Migrate Message payload construction and pattern matching from String/Vec<u8> to Utf8Bytes/Bytes.

Use case example: You’re building a real-time chat hub where clients send messages and the server also broadcasts events; the Skill guides the correct split+select pattern and the right Axum 0.8 Message types.

Quick Start

Add WebSocket support by routing a WebSocketUpgrade handler, enabling the Cargo ws feature, and implementing an on_upgrade callback that uses a concurrent split+select loop for send/receive.

Frequently Asked Questions about axum-impl-websockets

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement concurrent send and receive for Axum websockets without blocking?

To implement concurrent Axum websockets, use `socket.split()` combined with `tokio::spawn` and `tokio::select!`. This prevents the sequential-only echo trap, allowing true bidirectional messaging for real-time chat or broadcast systems.

How do I migrate Axum websocket Message types from 0.7 to 0.8?

Migrating Axum websocket Message types from 0.7 to 0.8 requires changing payload construction and pattern matching from `String` and `Vec<u8>` to `Utf8Bytes` and `Bytes` to ensure type compatibility.

Why do my Axum websocket upgrades fail silently in production?

Axum websocket upgrades can fail silently if you omit the optional `on_failed_upgrade` callback. Implementing `WebSocketUpgrade.on_upgrade` alongside `on_failed_upgrade` ensures upgrade failures are visible.

Do I need to enable a specific Cargo feature to use websockets in Axum?

Yes, you must enable the `ws` Cargo feature to use websockets in Axum. This feature gates the `WebSocketUpgrade` handler required to correctly wire and process WebSocket server endpoints.

Can I combine Axum websockets with connection metadata like ConnectInfo?

Yes, you can combine Axum websockets with state and connection metadata like `ConnectInfo`. This allows you to build robust endpoints that track client details during bidirectional messaging.

What is the best way to structure a real-time chat hub using Axum websockets?

The best way to structure a real-time chat hub using Axum websockets is applying a concurrent split+select loop pattern with `tokio::spawn` and utilizing version-aware 0.8 `Message` types for broadcasting.