Skip to main content

request_document

Function request_document 

Source
pub fn request_document(
    id: &RequestId,
    method: &MethodName,
    params: &JsonObject,
) -> Result<Value, RequestError>
Expand description

The request document, ready to frame.

§Errors

RequestError::UnreadableParams when the parameters cannot be read back as JSON, which a validated JsonObject should not be able to cause. It is a variant rather than an unwrap because the alternative is a claim this module cannot make, and because a panic on the path that runs for every request a client ever sends is the wrong place to defend a hypothesis.

§Examples

use protocol_droid::application::jsonrpc::document::request_document;
use protocol_droid::domain::RequestId;
use protocol_droid::domain::ir::{JsonObject, MethodName};

let method = MethodName::new("tools/list")?;
let document = request_document(&RequestId::number(1), &method, &JsonObject::default())?;

assert_eq!(
    document.to_string(),
    r#"{"id":1,"jsonrpc":"2.0","method":"tools/list","params":{}}"#,
);