FastLED 3.9.15
Loading...
Searching...
No Matches

◆ test_get_endpoint()

void test_get_endpoint ( )

Definition at line 124 of file ClientValidationReal.h.

124 {
125 FL_WARN("\n=== Test 2: GET /get (Request Echo) ===");
126
127 fl::task::Promise<fl::net::http::Response> promise = fl::net::http::fetch_get("http://localhost:8081/get");
129
130 if (!result.ok()) {
131 FL_WARN("✗ FAILED: " << result.error_message());
132 tests_failed++;
133 state = FAILED;
134 return;
135 }
136
137 const fl::net::http::Response& resp = result.value();
138 if (resp.status() != 200) {
139 FL_WARN("✗ FAILED: Status " << resp.status() << " " << resp.status_text());
140 tests_failed++;
141 state = FAILED;
142 return;
143 }
144
145 if (!resp.is_json()) {
146 FL_WARN("✗ FAILED: Response is not JSON");
147 tests_failed++;
148 state = FAILED;
149 return;
150 }
151
152 fl::json data = resp.json();
153 fl::string origin = data["origin"] | fl::string("unknown");
154 fl::string url = data["url"] | fl::string("unknown");
155
156 if (origin == "unknown" || url == "unknown") {
157 FL_WARN("✗ FAILED: Invalid response structure");
158 tests_failed++;
159 state = FAILED;
160 return;
161 }
162
163 FL_WARN("✓ PASSED");
164 FL_WARN(" Origin: " << origin);
165 FL_WARN(" URL: " << url);
166 tests_passed++;
167}
int tests_passed
int tests_failed
TestState state
bool is_json() const
Check if response appears to contain JSON content.
Definition fetch.h:122
const fl::string & status_text() const
HTTP status text (like JavaScript response.statusText)
Definition fetch.h:89
int status() const
HTTP status code (like JavaScript response.status)
Definition fetch.h:86
fl::json json() const
Response body parsed as JSON (JavaScript-like API)
HTTP response class (unified interface)
Definition fetch.h:78
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
Definition promise.h:58
Result type for promise operations.
#define FL_WARN(X)
Definition log.h:276
fl::task::Promise< Response > fetch_get(const fl::string &url, const FetchOptions &request)
HTTP GET request.
PromiseResult< T > await_top_level(Promise< T > p)
Synchronously wait for a promise to complete (ONLY safe in top-level contexts)
Definition executor.h:186
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References fl::task::await_top_level(), FAILED, fl::net::http::fetch_get(), FL_WARN, fl::net::http::Response::is_json(), fl::net::http::Response::json(), state, fl::net::http::Response::status(), fl::net::http::Response::status_text(), tests_failed, and tests_passed.

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: