@nexa/http
No dependencies — an HTTP client + a reactive data layer, for use inside an island or a handler.
createApi()
import { createApi } from "@nexa/http";
const api = createApi({ baseURL: "https://api.miapp.com" });
await api.get("/products");
await api.post("/products", { name: "..." });Real get/post/put/delete. A non-2xx status throws HttpError { status, message }.
query()
import { query } from "@nexa/http";
const users = query({ key: "users", fetch: () => api.get("/users") });
users.data.value;
users.refetch();data/loading/error as @nexa/reactivity Signals. cachePolicy: cache-first (default) | network-first | stale-while-revalidate.
mutation()
import { mutation } from "@nexa/http";
const createUser = mutation({ execute: (nombre) => api.post("/users", { nombre }) });
await createUser.execute("Ana");The same Signals (data/loading/error) as query(), for an action the user triggers (create, edit, delete).
connectSSE()
import { connectSSE } from "@nexa/http";
const notifications = connectSSE({ url: "/events" });
notifications.data.value;A thin wrapper over the native EventSource. data is the last message, parsed as JSON when possible.
connectSocket()
import { connectSocket } from "@nexa/http";
const chat = connectSocket({ url: "wss://miapp.com/chat" });
chat.send({ text: "hola" });A wrapper over the native WebSocket. status reflects the real lifecycle; send() serializes objects as JSON automatically.
Reconnection with backoff
const chat = connectSocket({
url: "wss://miapp.com/chat",
reconnect: { maxAttempts: 10, baseDelayMs: 500, maxDelayMs: 15000 }
});reconnect: true (or an object to tweak the defaults) reconnects on its own with exponential backoff + jitter. status passes through "reconnecting" while it tries.