Crate twitch_highway

Crate twitch_highway 

Source
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 HeaderAccess trait
§Feature Flags
  • webhook-verify: Core verification only
  • webhook-http: Generic HTTP header support
  • webhook-axum: Axum framework support
  • webhook-actix: Actix-web framework support
  • webhook: 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 reconnection
  • websocket-router: Event router with handles
  • websocket: 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§

adsads
analyticsanalytics
bitsbits
cclsccls
channel_pointschannel-points
channelschannels
charitycharity
chatchat
clipsclips
conduitsconduits
entitlementsentitlements
eventsubeventsub
extensionsextensions
gamesgames
goalsgoals
guest_starguest-star
hype_trainhype-train
moderationmoderation
pollspolls
predictionspredictions
raidraid
request
scheduleschedule
searchsearch
streamsstreams
subscriptionssubscriptions
teamsteams
types
usersusers
videosvideos
whisperwhisper

Structs§

Error
TwitchAPI