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

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

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.

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<T: Serialize + DeserializeOwned> Request<T>
[src]

[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.

[src]

Helper to serialize the Request as json.

[src]

Helper to deserialize the Request from json.

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

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

[src]

Create a new Request with the specified params.

Trait Implementations

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

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

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

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