kode-bridge
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 dotenv;
use ;
use env;
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.