httpbin/
httpbin.rs

1use blockless_sdk::*;
2
3fn main() {
4    let mut opts = HttpOptions::new("GET", 30, 10);
5    opts.headers = Some(std::collections::BTreeMap::from([(
6        "X-Test".to_string(),
7        "123".to_string(),
8    )]));
9
10    let http = BlocklessHttp::open("http://httpbin.org/anything", &opts);
11    let http = http.unwrap();
12    let body = http.get_all_body().unwrap();
13    let body = String::from_utf8(body).unwrap();
14    let bodies = match json::parse(&body).unwrap() {
15        json::JsonValue::Object(o) => o,
16        _ => panic!("must be object"),
17    };
18
19    let headers = match bodies.get("headers") {
20        Some(json::JsonValue::Object(headers)) => headers,
21        _ => panic!("must be array"),
22    };
23    headers.iter().for_each(|s| {
24        println!("{} = {}", s.0, s.1);
25    });
26}