nexgenomics 0.2.4

The official Rust crate for NexGenomics
Documentation

// src/ping.rs

use crate::utils;
use reqwest::{Client,Error};
use reqwest::header::{AUTHORIZATION, HeaderValue};

use serde::Deserialize;

#[derive(Debug,Deserialize)]
pub struct Ping {
    api: String,
    host: String,
}

async fn inner_ping() -> Result<Ping, Error> {
    let auth_token = utils::get_api_auth_token().unwrap();
    let url_stem = utils::get_api_url_stem().unwrap();

    let token = format!("Bearer {}", auth_token);
    let url = format!("{}/api/v0/ping",url_stem);
    //println!("{}, {}", token, url);

    let client = Client::new();
    let response = client
        .get(url)
        .header (AUTHORIZATION, HeaderValue::from_str(&token).unwrap())
        .send()
        .await?
        .error_for_status()?;

    let p = response.json::<Ping>().await?;
    Ok(p)
    
}

#[cfg(feature = "async")]
pub async fn ping() -> Result<Ping,Error> {
    inner_ping().await
}


#[cfg(feature = "blocking")]
pub fn ping() -> Result<Ping,Error> {
    let rt = tokio::runtime::Runtime::new()
        .expect("Failed to create Tokio runtime");
    rt.block_on(inner_ping())
}