76class WasmFetchRequest;
78using FetchResponseCallback = fl::function<void(
const response&)>;
79extern WasmFetch wasm_fetch;
129 if (content_type.has_value()) {
169 case 200:
return "OK";
170 case 400:
return "Bad Request";
171 case 401:
return "Unauthorized";
172 case 403:
return "Forbidden";
173 case 404:
return "Not Found";
174 case 500:
return "Internal Server Error";
175 case 501:
return "Not Implemented";
176 case 502:
return "Bad Gateway";
177 case 503:
return "Service Unavailable";
178 default:
return "Unknown";
227 mOptions.headers[
"Content-Type"] =
"application/json";
fl::size active_requests() const
fl::unique_ptr< FetchEngineListener > mEngineListener
static FetchManager & instance()
void update() override
Update this async runner (called during async pumping)
void cleanup_completed_promises()
fl::vector< fl::promise< response > > mActivePromises
void register_promise(const fl::promise< response > &promise)
bool has_active_tasks() const override
Check if this runner has active tasks.
size_t active_task_count() const override
Get number of active tasks (for debugging/monitoring)
Internal fetch manager for promise tracking.
static Json parse(const fl::string &txt)
fl::size find(const char &value) const
Generic asynchronous task runner interface.
fetch_options & json(const fl::string &json_data)
Set JSON body with proper content type.
const fl::string & url() const
Get the URL for this request.
fetch_options & timeout(int timeout_ms)
Set timeout in milliseconds.
fetch_options & body(const fl::string &data)
Set request body.
fetch_options & header(const fl::string &name, const fl::string &value)
Add header.
fetch_options(const fl::string &url)
const RequestOptions & options() const
Get the options for this request.
friend class FetchManager
fetch_options & method(const fl::string &http_method)
Set HTTP method.
fetch_options(const fl::string &url, const RequestOptions &options)
Fetch options builder (fluent interface)
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
fl::Json json() const
Response body parsed as JSON (JavaScript-like API)
void set_body(const fl::string &body)
fl::optional< fl::string > get_content_type() const
Get content type convenience method.
static fl::string get_default_status_text(int status)
void set_text(const fl::string &body)
const fl::string & get_body_text() const
Response body as text (alternative to text())
fl::optional< fl::string > get_header(const fl::string &name) const
Get header value (like JavaScript response.headers.get())
void set_status_text(const fl::string &status_text)
void set_status(int status_code)
Set methods (internal use)
const fl::string & status_text() const
HTTP status text (like JavaScript response.statusText)
response(int status_code, const fl::string &status_text)
fl::Json parse_json_body() const
Parse JSON from response body with error handling.
void set_header(const fl::string &name, const fl::string &value)
fl_map< fl::string, fl::string > mHeaders
int status() const
HTTP status code (like JavaScript response.status)
bool ok() const
Check if response is successful (like JavaScript response.ok)
const fl::string & text() const
Response body as text (like JavaScript response.text())
fl::optional< fl::Json > mCachedJson
response(int status_code)
bool is_json() const
Check if response appears to contain JSON content.
HTTP response class (unified interface)
static const fl::size npos
FastLED's Elegant JSON Library: fl::Json
Implements the FastLED namespace macros.
fl::promise< response > fetch_head(const fl::string &url, const fetch_options &request)
HTTP HEAD request.
fl::promise< response > fetch_delete(const fl::string &url, const fetch_options &request)
HTTP DELETE request.
fl::promise< response > fetch_http_options(const fl::string &url, const fetch_options &request)
HTTP OPTIONS request.
void fetch_update()
Legacy manual update for fetch promises (use fl::async_run() for new code)
fl::promise< response > fetch_request(const fl::string &url, const RequestOptions &options)
Generic request with options (like fetch(url, options))
optional< T > make_optional(const T &value)
fl::promise< response > fetch_put(const fl::string &url, const fetch_options &request)
HTTP PUT request.
fl::size fetch_active_requests()
Get number of active requests.
fl::promise< response > execute_fetch_request(const fl::string &url, const fetch_options &request)
Internal helper to execute a fetch request and return a promise.
fl::promise< response > fetch_patch(const fl::string &url, const fetch_options &request)
HTTP PATCH request.
constexpr nullopt_t nullopt
fl::function< void(const response &)> FetchCallback
Callback type for simple fetch responses (backward compatible)
fl::promise< response > fetch_post(const fl::string &url, const fetch_options &request)
HTTP POST request.
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > fl_map
HeapVector< T, Allocator > vector
void fetch(const fl::string &url, const FetchCallback &callback)
Make an HTTP GET request (cross-platform, backward compatible)
fl::promise< response > fetch_get(const fl::string &url, const fetch_options &request)
HTTP GET request.
Promise-based fluent API for FastLED - standalone async primitives.
Generic asynchronous task management for FastLED.
fl_map< fl::string, fl::string > headers
RequestOptions(const fl::string &method_name)
Request options (matches JavaScript fetch RequestInit)