Struct jrpc::Request [] [src]

pub struct Request<M, T> {
    pub jsonrpc: V2_0,
    pub method: M,
    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".to_string(),
    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

A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".

A serializable method.

The spec states it must be a String containing the name of the method to be invoked. This library makes no guarantees about this. It is recomended to use a simple enum for your library's method.

Section 8: Extensions

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.

This library provides no way of checking for system extensions.

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.

The id. See Id

Methods

impl<M: Serialize + DeserializeOwned, T: Serialize + DeserializeOwned> Request<M, T>
[src]

[src]

Helper to serialize the Request as json.

[src]

Helper to deserialize the Request from json.

impl<M: Serialize + DeserializeOwned> Request<M, ()>
[src]

[src]

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".to_string(),
);
println!("{}", request.to_string());

impl<M: Serialize + DeserializeOwned, T: Serialize + DeserializeOwned> Request<M, T>
[src]

[src]

Create a new Request with the specified params.

Trait Implementations

impl<M: Debug, T: Debug> Debug for Request<M, T>
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<M, T> Send for Request<M, T> where
    M: Send,
    T: Send

impl<M, T> Sync for Request<M, T> where
    M: Sync,
    T: Sync