blocking/blocking.rs
1//! Blocking client against `typesafe-rs-mock`.
2//!
3//! ```text
4//! cargo run -p typesafe-rs --example blocking --features blocking
5//! ```
6
7use serde_json::json;
8use typesafe_rs::{ClientConfig, Question, questions};
9use typesafe_rs_mock::{MockServer, noul};
10
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let rt = tokio::runtime::Builder::new_multi_thread()
13 .enable_all()
14 .build()?;
15 let mock = rt.block_on(MockServer::start());
16 mock.on_system_one().respond(json!({
17 "urgent": noul(0.91),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build_blocking()?;
24
25 let response = client.system_one(
26 "Help! My payouts have been failing for 3 days.",
27 questions! { "urgent" => Question::noul("Does this convey urgency?") },
28 )?;
29 println!("urgent noul = {:?}", response.noul("urgent"));
30
31 drop(client);
32 drop(mock);
33 drop(rt);
34 Ok(())
35}