[−][src]Crate jsonrpc_v2
A very small and very fast JSON-RPC 2.0 server-focused framework.
Provides an integration for actix-web
servers.
Usage
use jsonrpc_v2::*; #[derive(serde::Deserialize)] struct TwoNums { a: usize, b: usize } fn add(Params(params): Params<TwoNums>) -> Result<usize, Error> { Ok(params.a + params.b) } fn sub(Params(params): Params<(usize, usize)>) -> Result<usize, Error> { Ok(params.0 - params.1) } fn message(state: State<String>) -> Result<String, Error> { Ok(String::from(&*state)) } fn main() -> Result<(), Box<dyn std::error::Error>> { let rpc = Server::with_state(String::from("Hello!")) .with_method("add", add) .with_method("sub", sub) .with_method("message", message) .finish(); actix_web::HttpServer::new(move || { let rpc = rpc.clone(); actix_web::App::new().service( actix_web::web::service("/api") .guard(actix_web::guard::Post()) .finish(rpc.into_web_service()), ) }) .bind("0.0.0.0:3000")? .run()?; Ok(()) }
Structs
NotificationBuilder | Builder struct for a notification request object |
Params |
|
RequestBuilder | Builder struct for a request object |
RequestObject | Request/Notification object |
Server | Server/request handler |
ServerBuilder | Builder used to add methods to a server |
State | A wrapper around the (optional) state object provided when creating the server |
Enums
Error | Error object in a response |
Id | Container for the request ID, which can be a string, number, or null. Not typically used directly. |
RequestKind | An enum to contain the different kinds of possible requests: using the provided
|
ResponseObject | The individual response object |
ResponseObjects | Container for the response object(s) or |
Traits
ErrorLike | Trait that can be used to map custom errors to the |
FromRequest | A trait to extract data from the request |