kode-bridge
δΈζ | English
kode-bridge is a modern Rust library that implements HTTP Over IPC for cross-platform (macOS, Linux, Windows) communication. It provides both client and server capabilities with elegant HTTP-style request/response and real-time streaming through Unix Domain Sockets or Windows Named Pipes, featuring a fluent API similar to reqwest with comprehensive connection pooling, advanced error handling, and high-performance streaming.
β¨ Features
- π True Cross-Platform: Automatically detects the platform and uses optimal IPC methods
- Unix/Linux/macOS: Unix Domain Sockets
- Windows: Named Pipes
- π Complete Client/Server Architecture:
- Client:
IpcHttpClient(HTTP-style request/response) +IpcStreamClient(real-time streaming) - Server:
IpcHttpServer(HTTP routing service) +IpcStreamServer(streaming broadcast service)
- Client:
- π Fluent API: Reqwest-inspired method chaining with type-safe JSON handling
- π¦ Auto Serialization: Built-in JSON request and response processing
- β‘ High Performance: Optimized connection management strategies for different platforms
- π§ Easy Integration: Based on interprocess and Tokio async runtime
- π Backward Compatible: Old API methods still work alongside new fluent interface
- π Complete Support: Includes examples, benchmarks, and comprehensive documentation
π Quick Start
Add Dependencies
[]
# Client only (default)
= "0.1"
# Server only
= { = "0.1", = ["server"] }
# Both client and server
= { = "0.1", = ["full"] }
# Required runtime
= { = "1", = ["full"] }
= { = "1.0", = ["derive"] }
= "1.0"
Available Features
client(default) - HTTP and streaming client functionalityserver- HTTP and streaming server functionalityfull- Both client and server capabilities
Basic Usage
use ;
use json;
use Duration;
async
Server Usage
use ;
use json;
async
Advanced Client Usage
use ;
use StreamExt;
async
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;
use env;
async
π Examples
Run built-in examples:
# Basic request example
# Large data request example
# Elegant HTTP client demo
# Elegant streaming client demo
# Two client comparison
# Real-time traffic monitoring
# HTTP server examples (requires server feature)
# Streaming server examples (requires server feature)
# Using custom IPC path
CUSTOM_SOCK=/tmp/my.sock CUSTOM_PIPE=\\\\.\\pipe\\my_pipe
π₯ Performance Benchmarks
Run performance benchmarks:
# Run all benchmarks
# View benchmark reports
Benchmarks automatically:
- Detect the running platform
- Use appropriate environment variables (
CUSTOM_SOCKorCUSTOM_PIPE) - Apply platform-specific performance optimization strategies
ποΈ Architecture Design
βββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
β CLIENT SIDE β SERVER SIDE β
βββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β IpcHttpClient β IpcStreamClient β IpcHttpServer β IpcStreamServer β
β (HTTP Req/Res) β (Real-time Stream) β (HTTP Routing)β (Stream Broadcast) β
βββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β Fluent API β Routing System β
β (HTTP-like Methods & Method Chaining) β (Request Handling & Response) β
βββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β http_client.rs β http_server.rs β
β (HTTP Protocol Handler) β (HTTP Protocol Server) β
βββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ€
β interprocess β
β (Cross-Platform IPC Transport) β
βββββββββββββββββββ¬ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ€
β Unix Sockets β Windows Pipes β Feature Flags β
β (Unix/Linux) β (Windows) β (client/server/full) β
βββββββββββββββββββ΄ββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ
Core Components
Client Components
IpcHttpClient: HTTP-style request/response client with fluent APIIpcStreamClient: Real-time streaming client for continuous data monitoring- Fluent API: Method chaining with
get(),post(),timeout(),json_body(),send(), etc.
Server Components
IpcHttpServer: HTTP server with routing system and middleware supportIpcStreamServer: Real-time streaming server with broadcast and multi-client management- Routing System: Express.js-like routing patterns with path parameters and query parameter support
Shared Components
http_client/server: Platform-agnostic HTTP protocol handling with chunked transfer encoding support- Smart Platform Detection: Compile-time automatic selection of optimal IPC implementation
- Feature Flags: Flexible compile-time functionality selection
API Comparison
| Feature | Old API | New Fluent API |
|---|---|---|
| GET Request | client.request("GET", "/path", None) |
client.get("/path").send() |
| POST with JSON | client.request("POST", "/path", Some(&json)) |
client.post("/path").json_body(&json).send() |
| Timeout | Not supported | client.get("/path").timeout(Duration::from_secs(5)).send() |
| Response Status | response.status |
response.status(), response.is_success() |
| JSON Parsing | response.json()? |
response.json::<T>()? with type inference |
| Streaming | Not available | stream_client.get("/events").json_results().await? |
π― Use Cases
- Local Service Communication: Communicate with local processes like Clash, Mihomo, proxy services, etc.
- Real-time Monitoring: Stream traffic data, logs, metrics, and system events in real-time
- Microservice Architecture: High-performance inter-process HTTP communication
- System Integration: Replace traditional REST API local calls with IPC
- Performance-Critical Applications: Scenarios requiring low-latency local communication
- Configuration Management: Dynamic configuration updates with immediate feedback
π οΈ Development
Build Project
Run Tests
Generate Documentation
π Resources
- Platform Guide - Detailed cross-platform usage guide
- Server Guide - Complete server development guide
- Examples - Complete example code (client and server)
- Benchmarks - Performance benchmarks
π€ Contributing
We welcome Issues and Pull Requests!
π License
This project is licensed under the Apache License 2.0.
See the Licence file for details.