Skip to main content

Read environment variables

Read values from FastEdge-defined environment variables in CDB Edge Compute programs.

Compute

Use this solution in your CDB Edge Compute service:

use fastedge::{
    body::Body,
    http::{Request, Response, StatusCode, Error},
};
use std::env;

#[fastedge::http]
fn main(_req: Request<Body>) -> Result<Response<Body>, Error> {
    // get value of version
    let version = match env::var("VERSION").ok() {
        None => return Response::builder()
                    .status(StatusCode::INTERNAL_SERVER_ERROR)
                    .body(Body::from("App misconfigured, missing mandatory parameter\n")),
        Some(val) => val
    };

    let mut body: String = "".to_string();
    body.push_str(&version);

    // build response with body and custom header
    Response::builder()
        .status(StatusCode::OK)
        .body(Body::from(body))
}
[package]
name = "http_read_variable"
version = "1.0.0"
edition = "2021"
authors = ["John Doe <john.doe@orange.com>"]
description = "Wasm example: Read a clear environment variable"

[dependencies]
fastedge = { git ="https://github.com/G-Core/FastEdgeSDK.git", version = "0.1.10", features = ["json"]}


[lib]
crate-type = ["cdylib"]