1 个稳定版本
使用旧的Rust 2015
7.1.0 | 2017年8月30日 |
---|
#1132 在 HTTP服务器
在 sputnikvm-dev 中使用
150KB
4K SLoC
jsonrpc-http-server
Rust使用JSON-RPC 2.0的HTTP服务器。
示例
Cargo.toml
[dependencies]
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc" }
jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc" }
main.rs
extern crate jsonrpc_core;
extern crate jsonrpc_http_server;
use jsonrpc_core::*;
use jsonrpc_http_server::*;
fn main() {
let mut io = IoHandler::default();
io.add_method("say_hello", |_| {
Ok(Value::String("hello".into()))
});
let server = ServerBuilder::new(io)
.cors(DomainsValidation::AllowOnly(vec![AccessControlAllowOrigin::Null]))
.start_http(&"127.0.0.1:3030".parse().unwrap())
.expect("Unable to start RPC server");
server.wait().unwrap();
}
lib.rs
:
jsonrpc http服务器。
extern crate jsonrpc_core;
extern crate jsonrpc_http_server;
use jsonrpc_core::*;
use jsonrpc_http_server::*;
fn main() {
let mut io = IoHandler::new();
io.add_method("say_hello", |_: Params| {
Ok(Value::String("hello".to_string()))
});
let _server = ServerBuilder::new(io).start_http(&"127.0.0.1:3030".parse().unwrap());
}
依赖
~13MB
~250K SLoC