| Crates.io | opencore-jsonrpc-rust |
| lib.rs | opencore-jsonrpc-rust |
| version | 0.1.0 |
| created_at | 2026-01-24 10:39:09.043587+00 |
| updated_at | 2026-01-24 10:39:09.043587+00 |
| description | A simple and elegant library for creating JSON-RPC servers that communicate with the TypeScript framework OpenCore via stdin/stdout |
| homepage | https://opencorejs.dev |
| repository | https://github.com/Flussen/opencore-jsonrpc-rust |
| max_upload_size | |
| id | 2066515 |
| size | 32,795 |
A simple and elegant library for creating JSON-RPC servers that communicate with TypeScript frameworks via stdin/stdout.
Add this to your Cargo.toml:
[dependencies]
opencore-jsonrpc-rust = "0.1.0"
use opencore_jsonrpc_rust::server::BinaryServer;
use serde_json::Value;
fn add(params: Vec<Value>) -> Result<Value, String> {
if params.len() != 2 {
return Err("Expected 2 parameters".into());
}
let a = params[0].as_i64().ok_or("Invalid number")?;
let b = params[1].as_i64().ok_or("Invalid number")?;
Ok(Value::from(a + b))
}
fn main() {
let mut server = BinaryServer::new();
server.register("add", add);
server.run();
}
Requests are sent as line-delimited JSON to stdin:
{"id": "req-123", "action": "add", "params": [5, 10]}
Responses are written as line-delimited JSON to stdout:
Success:
{"status": "ok", "id": "req-123", "result": 15}
Error:
{"status": "error", "id": "req-123", "error": "Invalid parameters"}
use opencore_jsonrpc_rust::server::BinaryServer;
use serde_json::Value;
fn multiply(params: Vec<Value>) -> Result<Value, String> {
if params.len() != 2 {
return Err("Expected 2 parameters".into());
}
let a = params[0].as_f64().ok_or("Invalid number")?;
let b = params[1].as_f64().ok_or("Invalid number")?;
Ok(Value::from(a * b))
}
fn main() {
let mut server = BinaryServer::new();
server.register("multiply", multiply);
server.run();
}
use opencore_jsonrpc_rust::server::BinaryServer;
use serde_json::Value;
fn concat(params: Vec<Value>) -> Result<Value, String> {
let strings: Result<Vec<String>, String> = params
.iter()
.map(|v| {
v.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "All parameters must be strings".to_string())
})
.collect();
Ok(Value::from(strings?.join("")))
}
fn main() {
let mut server = BinaryServer::new();
server.register("concat", concat);
server.run();
}
use opencore_jsonrpc_rust::server::BinaryServer;
use serde_json::{json, Value};
fn process_user(params: Vec<Value>) -> Result<Value, String> {
let user = params.first().ok_or("No user data provided")?;
let name = user["name"].as_str().ok_or("Missing name")?;
let age = user["age"].as_i64().ok_or("Missing age")?;
Ok(json!({
"message": format!("Hello, {}!", name),
"is_adult": age >= 18
}))
}
fn main() {
let mut server = BinaryServer::new();
server.register("process_user", process_user);
server.run();
}
Here's how to use this library from TypeScript (Using OpenCore Framework):
import { Server } from '@open-core/framework/server'
@Server.BinaryService({
name: 'math',
binary: 'math',
timeoutMs: 2000,
})
export class MathBinaryService {
@Server.BinaryCall({ action: 'sum' })
sum(a: number, b: number): Promise<number> {
throw new Error('BinaryCall proxy')
// or return null as any
}
}
Handlers should return Result<Value, String>:
Ok(value) - Success with a JSON valueErr(message) - Error with a descriptive messageThe server automatically handles:
Run the test suite:
cargo test
Run with output:
cargo test -- --nocapture
Generate and view the full API documentation:
cargo doc --open
MIT
Contributions are welcome! Please ensure:
cargo test)cargo fmt)cargo clippy)