client/
client.rs

1// In your own Cargo.toml, add the dependency `url`.
2// See this crate's Cargo.toml for the versions of these dependencies which
3// are currently used in `raystack`.
4
5use std::error::Error;
6
7fn main() -> Result<(), Box<dyn Error>> {
8    use raystack_blocking::{SkySparkClient, ValueExt};
9    use url::Url;
10
11    let url = Url::parse("https://www.example.com/api/projName/")?;
12
13    // If you are going to create many `SkySparkClient`s,
14    // reuse the same `reqwest::Client` in each `SkySparkClient`
15    // by using the `SkySparkClient::new_with_client` function instead.
16    let mut client = SkySparkClient::new(url, "username", "p4ssw0rd")?;
17
18    let sites_grid = client.eval("readAll(site)")?;
19
20    // Print the raw JSON:
21    println!("{}", sites_grid.to_json_string_pretty());
22
23    // Working with the Grid struct:
24    println!("All columns: {:?}", sites_grid.cols());
25    println!(
26        "first site id: {:?}",
27        sites_grid.rows()[0]["id"].as_hs_ref().unwrap()
28    );
29
30    Ok(())
31}