-
Notifications
You must be signed in to change notification settings - Fork 39
/
get_health.rs
36 lines (28 loc) · 1022 Bytes
/
get_health.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! This example returns the health of the node by querying its `/health` endpoint.
//!
//! Rename `.env.example` to `.env` first, then run the command:
//! ```sh
//! cargo run --release --all-features --example get_health [NODE_URL]
//! ```
use iota_sdk::client::{Client, Result};
#[tokio::main]
async fn main() -> Result<()> {
// If not provided we use the default node from the `.env` file.
dotenvy::dotenv().ok();
// Take the node URL from command line argument or use one from env as default.
let node_url = std::env::args()
.nth(1)
.unwrap_or_else(|| std::env::var("NODE_URL").expect("NODE_URL not set"));
// Create a node client.
let client = Client::builder()
.with_node(&node_url)?
.with_ignore_node_health()
.finish()
.await?;
// Get node health.
let is_healthy = client.get_health(&node_url).await?;
println!("Healthy: {is_healthy}");
Ok(())
}