Struct jrpc::Request
[−]
[src]
pub struct Request<T> { pub jsonrpc: V2_0, pub method: String, pub params: Option<T>, pub id: IdReq, }
A rpc call is represented by sending a Request object to a Server.
See the parameters for details.
Examples
extern crate serde_json; use jrpc::{Id, Request, V2_0}; let value: Vec<u32> = vec![1, 2, 3]; let request = Request::with_params( Id::from(4), "CreateFoo", Some(value.clone()), ); let json = r#" { "jsonrpc": "2.0", "method": "CreateFoo", "params": [1,2,3], "id": 4 } "#; let json = json.replace("\n", "").replace(" ", ""); let result = serde_json::to_string(&request).unwrap(); assert_eq!(json, result);
Fields
jsonrpc: V2_0
A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
method: String
A String containing the name of the method to be invoked.
Method names that begin with the word rpc followed by a period character ('.'
, U+002E
or ASCII 0x2e
) are reserved for rpc-internal methods and extensions and MUST NOT be used
for anything else.
params: Option<T>
A Structured value that holds the parameter values to be used during the invocation of the method.
Spec Requiement
Note: the following spec is not upheld by this library.
If present, parameters for the rpc call MUST be provided as a Structured value. Either by-position through an Array or by-name through an Object.
- by-position: params MUST be an Array, containing the values in the Server expected order.
- by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.
id: IdReq
The id
. See Id
Methods
impl<T: Serialize + DeserializeOwned> Request<T>
[src]
pub fn is_system_extension(&self) -> bool
[src]
Return whether the method name is defined as a system extension.
Method names that begin with "rpc."
are reserved for system extensions, and MUST NOT be
used for anything else. Each system extension is defined in a related specification. All
system extensions are OPTIONAL.
pub fn to_string(&self) -> String
[src]
Helper to serialize the Request as json.
pub fn from_str(s: &str) -> Result<T>
[src]
Helper to deserialize the Request from json.
impl Request<()>
[src]
pub fn new<I, S>(id: I, method: S) -> Self where
I: Into<IdReq>,
S: Into<String>,
[src]
I: Into<IdReq>,
S: Into<String>,
Create a new Request.
Examples
extern crate jrpc;
extern crate serde_json; use jrpc::{Id, Request}; let value: Vec<u32> = vec![1, 2, 3]; let request = Request::new( Id::from(4), "CreateFoo" ); println!("{}", request.to_string());
impl<T: Serialize + DeserializeOwned> Request<T>
[src]
pub fn with_params<I, S>(id: I, method: S, params: T) -> Self where
I: Into<IdReq>,
S: Into<String>,
[src]
I: Into<IdReq>,
S: Into<String>,
Create a new Request with the specified params.