Expand description
§twitch_highway
A Rust library for the Twitch Helix API with type safety and comprehensive EventSub support.
Official Twitch API Documentation: https://dev.twitch.tv/docs/api/reference/
§Getting Started
Important: By default, no API endpoints are enabled. You must specify the features you need in Cargo.toml.
[dependencies]
twitch_highway = { version = "0.3", features = ["moderation", "chat"] }
tokio = { version = "1", features = ["full"] }
asknothingx2-util = { version = "0.1", features = ["oauth"] }§Basic Usage
use asknothingx2_util::oauth::{AccessToken, ClientId};
use twitch_highway::{
moderation::ModerationAPI,
types::{BroadcasterId, ModeratorId, UserId},
TwitchAPI,
};
let api = TwitchAPI::new(
AccessToken::from("your_access_token"),
ClientId::from("your_client_id"),
);
let response = api
.ban_user(
&BroadcasterId::from("12345"),
&ModeratorId::from("67890"),
&UserId::from("54321"),
)
.duration(600) // Optional
.reason("no reason") // Optional: 10 minues
.json()
.await?;
println!("User banned successfully");§Error Handling
match api.json().await {
Ok(response) => {
// Process successful response
}
Err(e) => {
if e.is_request() {
// Network or connection error
eprintln!("Request failed: {}", e);
} else if e.is_api() {
// Twitch API returned an error (4xx, 5xx)
eprintln!("API error: {}", e);
} else if e.is_decode() {
// Failed to parse JSON response
eprintln!("JSON decode error: {}", e);
}
}
}§EventSub Integration
Comprehensive support for both Webhook and WebSocket transports.
§Webhook Verification
- HMAC-SHA256 signature verification
- Framework integrations: axum, actix-web
- Custom implementations via
HeaderAccesstrait
§Feature Flags
webhook-verify: Core verification onlywebhook-http: Generic HTTP header supportwebhook-axum: Axum framework supportwebhook-actix: Actix-web framework supportwebhook: All webhook features
§WebSocket Client
- Automatic reconnection with exponential backoff
- Keepalive message handling
- Type-safe event routing (similar to axum)
- Middleware support (logging, rate limiting)
§Feature Flags
websocket-client: Client with reconnectionwebsocket-router: Event router with handleswebsocket: All WebSocket features
See the eventsub module documentation for more details.
§OAuth Token Management
This library is designed to work with twitch_oauth_token for OAuth authentication:
[dependencies]
twitch_oauth_token = "2.0"§API Endpoint Features
§Features
Modules§
- ads
ads - analytics
analytics - bits
bits - ccls
ccls - channel_
points channel-points - channels
channels - charity
charity - chat
chat - clips
clips - conduits
conduits - entitlements
entitlements - eventsub
eventsub - extensions
extensions - games
games - goals
goals - guest_
star guest-star - hype_
train hype-train - moderation
moderation - polls
polls - predictions
predictions - raid
raid - request
- schedule
schedule - search
search - streams
streams - subscriptions
subscriptions - teams
teams - types
- users
users - videos
videos - whisper
whisper