kode-bridge 0.1.3

Cross-platform Rust library for sending HTTP requests over IPC channels (Unix sockets, planned Windows named pipes).
Documentation

kode-bridge

Rust License Crates.io

δΈ­ζ–‡ | English

kode-bridge is a modern Rust library designed for cross-platform (macOS, Linux, Windows) IPC HTTP communication. With a unified API, you can easily send HTTP requests via Unix Domain Sockets or Windows Named Pipes, just as simple as using a regular HTTP client.

✨ Features

  • 🌍 True Cross-Platform: Automatically detects the platform and uses optimal IPC methods
    • Unix/Linux/macOS: Unix Domain Sockets
    • Windows: Named Pipes
  • πŸš€ Zero Configuration: Unified IpcHttpClient API, no platform-specific code required
  • πŸ“¦ Auto Serialization: Built-in JSON request and response handling
  • ⚑ High Performance: Optimized connection management strategies for different platforms
  • πŸ”§ Easy Integration: Based on interprocess and Tokio async runtime
  • πŸ“– Complete Support: Includes examples, benchmarks, and comprehensive documentation

πŸš€ Quick Start

Add Dependencies

[dependencies]
kode-bridge = "0.1"
tokio = { version = "1", features = ["full"] }
serde_json = "1.0"

Basic Usage

use kode_bridge::IpcHttpClient;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Automatically detect platform and use appropriate IPC path
    #[cfg(unix)]
    let client = IpcHttpClient::new("/tmp/my_service.sock")?;
    
    #[cfg(windows)]
    let client = IpcHttpClient::new(r"\\.\pipe\my_service")?;
    
    // Send GET request
    let response = client.request("GET", "/api/version", None).await?;
    println!("Status: {}", response.status);
    println!("Response: {}", response.body);
    
    // Send POST request
    let data = json!({"user": "alice", "action": "login"});
    let response = client.request("POST", "/api/auth", Some(&data)).await?;
    println!("Auth result: {}", response.json()?);
    
    Ok(())
}

Using Environment Variables

Create a .env file:

# Unix systems
CUSTOM_SOCK=/tmp/my_app.sock

# Windows systems (each backslash needs to be escaped by doubling)
CUSTOM_PIPE=\\\\.\\pipe\\\my_app

Then in your code:

use dotenv::dotenv;
use std::env;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    dotenv().ok();
    
    #[cfg(unix)]
    let path = env::var("CUSTOM_SOCK").unwrap_or("/tmp/default.sock".to_string());
    
    #[cfg(windows)]
    let path = env::var("CUSTOM_PIPE").unwrap_or(r"\\.\pipe\default".to_string());
    
    let client = IpcHttpClient::new(&path)?;
    let response = client.request("GET", "/status", None).await?;
    
    Ok(())
}

πŸ“‹ Examples

Run built-in examples:

# Basic request example
cargo run --example request

# Large data request example
cargo run --example request_large

# Using custom IPC path
CUSTOM_SOCK=/tmp/my.sock cargo run --example request  # Unix
CUSTOM_PIPE=\\\\.\\pipe\\my_pipe cargo run --example request  # Windows

πŸ”₯ Performance Benchmarks

Run performance benchmarks:

# Run all benchmarks
cargo bench

# View benchmark reports
open target/criterion/report/index.html

Benchmarks automatically:

  • Detect the running platform
  • Use appropriate environment variables (CUSTOM_SOCK or CUSTOM_PIPE)
  • Apply platform-specific performance optimization strategies

πŸ—οΈ Architecture Design

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              IpcHttpClient              β”‚
β”‚       (Unified Cross-Platform API)      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚            http_client.rs               β”‚
β”‚        (HTTP Protocol Handler)          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚             interprocess                β”‚
β”‚       (Cross-Platform IPC Transport)    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   Unix Sockets  β”‚    Windows Pipes      β”‚
β”‚   (Unix/Linux)  β”‚     (Windows)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

  • IpcHttpClient: Unified client interface that automatically adapts to different platforms
  • http_client: Platform-agnostic HTTP protocol handling with chunked transfer encoding support
  • Smart Platform Detection: Compile-time automatic selection of optimal IPC implementation

🎯 Use Cases

  • Local Service Communication: Communicate with local processes like Clash, Mihomo, proxy services, etc.
  • Microservice Architecture: High-performance inter-process HTTP communication
  • System Integration: Replace traditional REST API local calls
  • Performance-Critical Applications: Scenarios requiring low-latency local communication

πŸ› οΈ Development

Build Project

git clone https://github.com/KodeBarinn/kode-bridge.git
cd kode-bridge
cargo build

Run Tests

cargo test

Generate Documentation

cargo doc --open

πŸ“š Resources

🀝 Contributing

We welcome Issues and Pull Requests!

πŸ“„ License

This project is licensed under the Apache License 2.0.

See the Licence file for details.