| Crates.io | twitch_highway |
| lib.rs | twitch_highway |
| version | 0.3.3 |
| created_at | 2024-03-02 04:54:10.539756+00 |
| updated_at | 2026-01-19 03:37:28.669598+00 |
| description | Twitch API |
| homepage | |
| repository | https://github.com/m3idnotfree/twitch_highway.git |
| max_upload_size | |
| id | 1159489 |
| size | 1,228,832 |
A Rust library for the Twitch API with compile-time safety and comprehensive response support.
[dependencies]
# Add the endpoints you need: "chat", "users", etc.
twitch_highway = { version = "0.3", features = ["moderation"] }
tokio = { version = "1", features = ["full"] }
asknothingx2-util = { version = "0.1", features = ["oauth"] }
# or
# twitch_oauth_token = { version = "2" }
use asknothingx2_util::oauth::{AccessToken, ClientId};
// or
// use twitch_oauth_token::oauth::{AccessToken, ClientId};
use twitch_highway::{
moderation::ModerationAPI,
types::{BroadcasterId, ModeratorId, UserId},
TwitchAPI,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api = TwitchAPI::new(
AccessToken::from("access_token".to_string()),
ClientId::from("client_id".to_string()),
);
let broadcaster_id = BroadcasterId::from("broadcaster_id");
let moderator_id = ModeratorId::from("moderator_id");
let user_id = UserId::from("9876");
let response = api.ban_user(&broadcaster_id, &moderator_id, &user_id)
.reason("no reason")
.duration(600) // 10 minutes
.json()
.await;
match response {
Ok(success) => { /* */ }
Err(e) => {
if e.is_api() {
println!("API error: {}", e);
} else if e.is_request() {
println!("Request error: {}", e);
} else if e.is_decode() {
println!("JSON decode error: {}", e);
} else {
println!("Unexpected error: {}", e)
}
}
}
Ok(())
}
[dependencies]
twitch_highway = { version = "0.3", features = ["eventsub", "webhook-axum"] }
axum = "0.8"
use axum::{
body::{Body, Bytes},
http::{header::HeaderMap, StatusCode},
response::Response,
routing::post,
Router,
};
use twitch_highway::eventsub::webhook::{verify_event_message, VerificationError};
async fn webhook_handler(headers: HeaderMap, body: Bytes) -> Result<Response, VerificationError> {
verify_event_message(&headers, &body, "your_webhook_secret")?;
Ok(Response::builder()
.status(StatusCode::NO_CONTENT)
.body(Body::empty())
.unwrap())
}
let app = Router::new().route("/webhook", post(webhook_handler));
[dependencies]
twitch_highway = { version = "0.3", features = ["eventsub", "websocket"] }
use twitch_highway::eventsub::{
events::channels::follow::ChannelFollow,
websocket::{self, extract::Event, routes::channel_follow, Router},
};
async fn on_follow(Event(event): Event<ChannelFollow>) {
println!("New follower: {}", event.user_name);
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error> {
let app = Router::new().route(channel_follow(on_follow));
websocket::client("wss://eventsub.wss.twitch.tv/ws", app).await?;
Ok(())
}
Enable only the API modules you need:
webhook: All webhook features (verification, framework integrations)webhook-verify: Core signature verificationwebhook-axum: Axum framework integrationwebhook-actix: Actix-web framework integrationwebsocket: WebSocket client with routingwebsocket-client: WebSocket client onlywebsocket-router: Event router with middlewareLicensed under either of