HTTP
Thin wrapper around fetch with AbortController timeout, JSON sugar and ergonomic helpers.
request
js
const res = await F.http.request("/api/user", {
method: "POST",
json: { name: "Ada" }, // auto JSON.stringify + Content-Type
headers: { "X-Token": "…" },
timeout: 5000 // aborts via AbortController
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);On non-2xx, Flash throws Error with error.status and error.response (the Response).
Helpers
js
const user = await F.http.json("/api/user/42");
const text = await F.http.text("/api/readme");
const blob = await F.http.blob("/api/file");
const buf = await F.http.arrayBuffer("/api/file");
const res1 = await F.http.get("/api/data", { timeout: 3000 });
await F.http.post("/api/user", JSON.stringify({ name: "Ada" }));
await F.http.put("/api/user/1", body);
await F.http.patch("/api/user/1", body);
await F.http.delete("/api/user/1");ESM-only import:
import { http } from "flash.js/http" — tree-shakable if you only need HTTP.Error handling
js
try {
const data = await F.http.json("/api/user/1", { timeout: 4000 });
} catch (e) {
if (e.status === 404) F.toast("Not found","error");
else if (e.name === "AbortError") F.toast("Timeout","warn");
else F.toast(e.message,"error");
}Live demo
—