{
"id": "274",
"prompt": "I want a little fetch dashboard: fire ONE host::http::get of https://example.com/ behind an init latch (the URL is a string literal - http::get is one of the few String-typed host params), poll ready(handle) every frame, and drive a full-width status strip amber/green/red from the phase. When the body lands print the UPSTREAM HTTP status and body_len in big digits; on error say the proxy denied it. ready() is 0 pending, 1 ready, negative on failure.",
"solution_rl": "fn frame(t: i32) {\n host::display::clear(0x0e1014);\n if host::display::state_get(0) == 0 {\n let h: i32 = host::http::get(\"https://example.com/\", 20);\n host::display::state_set(1, h);\n if h < 0 {\n host::display::state_set(0, 3);\n } else {\n host::display::state_set(0, 1);\n }\n }\n if host::display::state_get(0) == 1 {\n let h2: i32 = host::display::state_get(1);\n let r: i32 = host::http::ready(h2);\n if r == 1 {\n host::display::state_set(0, 2);\n } else if r < 0 {\n host::display::state_set(0, 3);\n }\n }\n let phase: i32 = host::display::state_get(0);\n host::display::draw_string(96, 60, \"FETCH DASHBOARD\", 0xffffff, 2);\n let mut bar: i32 = 0xaa7700;\n if phase == 2 {\n bar = 0x22bb44;\n } else if phase == 3 {\n bar = 0xbb2222;\n }\n host::display::fill_rect(0, 0, 512, 8, bar);\n if phase == 1 {\n host::display::draw_string(96, 200, \"REQUEST IN FLIGHT\", 0xaa7700, 2);\n if (t / 20) % 2 == 0 {\n host::display::fill_rect(320, 198, 14, 14, 0xaa7700);\n }\n } else if phase == 2 {\n let h3: i32 = host::display::state_get(1);\n host::display::draw_string(96, 160, \"UPSTREAM STATUS\", 0x888888, 1);\n host::display::draw_number(96, 180, host::http::status(h3), 0x66ddff, 4);\n host::display::draw_string(96, 280, \"BODY BYTES\", 0x888888, 1);\n host::display::draw_number(96, 300, host::http::body_len(h3), 0xffffff, 4);\n } else {\n host::display::draw_string(96, 200, \"FETCH FAILED\", 0xbb2222, 3);\n host::display::draw_string(96, 250, \"BAD URL OR DENIED BY THE PROXY\", 0x777777, 1);\n }\n host::display::present();\n}\n",
"tags": [
"http",
"fetch",
"poll-model"
]
}