Function kubos_app::query [−][src]
pub fn query(
config: ServiceConfig,
query: &str,
timeout: Option<Duration>
) -> Result<Value, Error>
Execute a GraphQL query against a running KubOS Service using UDP.
Returns the parsed JSON result as a serde_json::Value on success
Arguments
service
- The name of the service to send the query toconfig_path
- The system location of theconfig.toml
file which has the IP and port information of the service to query. IfNone
is specified, the default config location will be usedquery
- The raw GraphQL query as a stringtimeout
- The timeout provided to the UDP socket. Note: This function will block whenNone
is provided here
Examples
use kubos_app::*; use std::time::Duration; let request = r#"{ ping }"#; let result = query(ServiceConfig::new_from_path("radio-service", "/home/kubos/config.toml".to_owned()), request, Some(Duration::from_secs(1)))?; let data = result.get("ping").unwrap().as_str(); assert_eq!(data, Some("pong"));
use kubos_app::*; use std::time::Duration; let request = r#"{ power }"#; let result = query(ServiceConfig::new("antenna-service"), request, Some(Duration::from_secs(1)))?; let data = result.get("power").unwrap().as_str(); assert_eq!(data, Some("ON"));