Skip to main content

league_link/
lib.rs

1//! # league-link
2//!
3//! An async Rust client for the League of Legends Client (LCU) API.
4//!
5//! `league-link` provides three primitives:
6//!
7//! 1. **Credential discovery** — [`authenticate`] / [`try_find_lcu`] /
8//!    [`try_find_lcu_async`] / [`try_find_lcu_via_lockfile`] locate a running
9//!    client and extract its local API port and auth token.
10//! 2. **HTTP requests** — [`build_lcu_client`] + [`lcu_get`] / [`lcu_post`]
11//!    / [`lcu_delete`] issue typed requests against the local HTTPS server.
12//! 3. **WebSocket events** — [`ws_connect`] or [`ws_connect_filtered`]
13//!    subscribe to LCU events and deliver them through an [`EventStream`].
14//!
15//! ## Example
16//!
17//! ```no_run
18//! use league_link::{authenticate, build_lcu_client, lcu_get, ws_connect};
19//! use serde_json::Value;
20//!
21//! # async fn run() -> Result<(), league_link::LcuError> {
22//! // 1. Find the running client
23//! let creds = authenticate(1000, 30).await?;
24//!
25//! // 2. Make an HTTP call
26//! let client = build_lcu_client()?;
27//! let me: Value = lcu_get(&client, &creds, "/lol-summoner/v1/current-summoner").await?;
28//! println!("summoner: {me}");
29//!
30//! // 3. Watch live events
31//! let mut stream = ws_connect(&creds, 128).await?;
32//! while let Some(event) = stream.recv().await {
33//!     println!("[{:?}] {}", event.event_type, event.uri);
34//! }
35//! # Ok(()) }
36//! ```
37
38#![forbid(unsafe_code)]
39#![warn(missing_docs)]
40
41pub mod auth;
42/// Unified error type returned by every fallible operation in this crate.
43pub mod error;
44pub mod http;
45pub mod websocket;
46
47pub use auth::{
48    authenticate, try_find_lcu, try_find_lcu_async, try_find_lcu_via_lockfile, Credentials,
49};
50pub use error::LcuError;
51pub use http::{
52    build_lcu_client, lcu_delete, lcu_get, lcu_post, lcu_request, lcu_request_with_body,
53    parse_marketing_version, DEFAULT_TIMEOUT,
54};
55pub use websocket::{
56    connect as ws_connect, connect_filtered as ws_connect_filtered, EventStream, EventType,
57    LcuEvent,
58};