Skip to main content

get

Function get 

Source
pub fn get(name: &str) -> Result<String, Error>
Expand description

Get the value of a component variable.

ยงExamples

Get the value of a component variable.

let region = spin_sdk::variables::get("region_id")?;
let regional_url = format!("https://{region}.db.example.com");

Fail gracefully if a variable is not set.

use spin_sdk::variables::Error;

let favourite = match spin_sdk::variables::get("favourite") {
    Ok(value) => value,
    Err(Error::Undefined(_)) => "not playing favourites".to_owned(),
    Err(e) => anyhow::bail!(e),
};

Get an application variable value for the current component.

The name must match one defined in in the component manifest.