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/fetch.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()
bool ok() const
Check if response is successful (like JavaScript response.ok)
Definition fetch.h:97
const fl::string & text() const
Response body as text (like JavaScript response.text())
Definition fetch.h:100
HTTP response class (unified interface)
Definition fetch.h:83
Unified HTTP fetch API for FastLED (cross-platform)
void fetch(const fl::string &url, const FetchCallback &callback)
Make an HTTP GET request (cross-platform, backward compatible)
Definition fetch.cpp:63
#define FL_WARN
Definition warn.h:12

Usage

#include "fl/fetch.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::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.
Definition FastLED.cpp:74
const fl::string & status_text() const
HTTP status text (like JavaScript response.statusText)
Definition fetch.h:94
int status() const
HTTP status code (like JavaScript response.status)
Definition fetch.h:91
fl::promise< response > fetch_get(const fl::string &url, const fetch_options &request)
HTTP GET request.
Definition fetch.cpp:180
fl::string message
Definition promise.h:54
Error type for promises.
Definition promise.h:53

Definition in file fetch.h.

#include "fl/namespace.h"
#include "fl/promise.h"
#include "fl/string.h"
#include "fl/vector.h"
#include "fl/map.h"
#include "fl/hash_map.h"
#include "fl/optional.h"
#include "fl/function.h"
#include "fl/ptr.h"
#include "fl/async.h"
#include "fl/mutex.h"
#include "fl/warn.h"
#include "fl/json.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::fetch_options
 Fetch options builder (fluent interface) More...
 
class  fl::FetchManager
 Internal fetch manager for promise tracking. More...
 
struct  fl::RequestOptions
 Request options (matches JavaScript fetch RequestInit) More...
 
class  fl::response
 HTTP response class (unified interface) More...
 

Namespaces

namespace  fl
 IMPORTANT!
 

Typedefs

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

Functions

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