FastLED 3.9.15
Loading...
Searching...
No Matches
fetch.h File Reference

Detailed Description

Unified HTTP fetch API for FastLED (cross-platform)

This API provides both simple callback-based and JavaScript-like promise-based interfaces for HTTP requests. Works on WASM/browser platforms with real fetch, provides stubs on embedded.

WASM Optimization: On WASM platforms, delay() automatically pumps all async tasks (fetch, timers, etc.) in 1ms intervals, making delay time useful for processing async operations.

Callback Usage

#include "fl/net/http.h"
void setup() {
// Simple callback-based fetch (backward compatible)
fl::fetch("http://fastled.io", [](const fl::Response& resp) {
if (resp.ok()) {
FL_WARN("Success: " << resp.text());
}
});
}
void setup()
fl::net::http — High-level HTTP client and server facade
#define FL_WARN(X)
Definition log.h:276

Usage

#include "fl/net/http.h"
void setup() {
// JavaScript-like fetch with promises
fl::fetch_get("http://fastled.io")
.then([](const fl::Response& resp) {
if (resp.ok()) {
FL_WARN("Success: " << resp.text());
} else {
FL_WARN("HTTP Error: " << resp.status() << " " << resp.status_text());
}
})
.catch_([](const fl::task::Error& err) {
FL_WARN("Fetch Error: " << err.message);
});
}
void loop() {
// Fetch promises are automatically updated through FastLED's engine events!
// On WASM platforms, delay() also pumps all async tasks automatically.
// No manual updates needed - just use normal FastLED loop
FastLED.show();
delay(16); // delay() automatically pumps all async tasks on WASM
}
void loop()
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
void delay(u32 ms, bool run_async=true) FL_NOEXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
Definition delay.h:98
fl::string message
Definition promise.h:40
Error type for promises.
Definition promise.h:39

Definition in file fetch.h.

#include "fl/task/promise.h"
#include "fl/stl/string.h"
#include "fl/stl/vector.h"
#include "fl/stl/map.h"
#include "fl/stl/unordered_map.h"
#include "fl/stl/optional.h"
#include "fl/stl/function.h"
#include "fl/stl/shared_ptr.h"
#include "fl/task/executor.h"
#include "fl/stl/mutex.h"
#include "fl/log/log.h"
#include "fl/stl/json.h"
#include "fl/stl/noexcept.h"
+ Include dependency graph for fetch.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  fl::net::http::FetchManager
 Internal fetch manager for promise tracking. More...
 
class  fl::net::http::FetchOptions
 Fetch options builder (fluent interface) More...
 
struct  fl::net::http::RequestOptions
 Request options (matches JavaScript fetch RequestInit) More...
 
class  fl::net::http::Response
 HTTP response class (unified interface) More...
 

Namespaces

namespace  fl
 Base definition for an LED controller.
 
namespace  fl::net
 
namespace  fl::net::http
 

Typedefs

using fl::net::http::FetchCallback = fl::function<void(const Response&)>
 Callback type for simple fetch responses (backward compatible)
 

Functions

fl::task::Promise< Responsefl::net::http::execute_fetch_request (const fl::string &url, const FetchOptions &request)
 Internal helper to execute a fetch request and return a promise.
 
void fl::net::http::fetch (const char *url, const FetchCallback &callback)
 Make an HTTP GET request with URL string literal (cross-platform)
 
void fl::net::http::fetch (const fl::string &url, const FetchCallback &callback)
 Make an HTTP GET request (cross-platform, backward compatible)
 
fl::size fl::net::http::fetch_active_requests ()
 Get number of active requests.
 
fl::task::Promise< Responsefl::net::http::fetch_delete (const fl::string &url, const FetchOptions &request=FetchOptions(""))
 HTTP DELETE request.
 
fl::task::Promise< Responsefl::net::http::fetch_get (const fl::string &url, const FetchOptions &request=FetchOptions(""))
 HTTP GET request.
 
fl::task::Promise< Responsefl::net::http::fetch_head (const fl::string &url, const FetchOptions &request=FetchOptions(""))
 HTTP HEAD request.
 
fl::task::Promise< Responsefl::net::http::fetch_http_options (const fl::string &url, const FetchOptions &request=FetchOptions(""))
 HTTP OPTIONS request.
 
fl::task::Promise< Responsefl::net::http::fetch_patch (const fl::string &url, const FetchOptions &request=FetchOptions(""))
 HTTP PATCH request.
 
fl::task::Promise< Responsefl::net::http::fetch_post (const fl::string &url, const FetchOptions &request=FetchOptions(""))
 HTTP POST request.
 
fl::task::Promise< Responsefl::net::http::fetch_put (const fl::string &url, const FetchOptions &request=FetchOptions(""))
 HTTP PUT request.
 
fl::task::Promise< Responsefl::net::http::fetch_request (const fl::string &url, const RequestOptions &options=RequestOptions())
 Generic request with options (like fetch(url, options))
 
void fl::net::http::fetch_update ()
 Legacy manual update for fetch promises (use fl::task::run() for new code)