Minimal HTTP client utilities for the browser.
Provides exactly two primitives:
call- JSON-first POST requests with predictable error handlingsse- thin wrapper aroundEventSource
No abstractions beyond what the platform already gives you.
npm install @papack/clientTyped POST request helper.
import { call } from "@papack/client";
const result = await call<User>("/api/user", { id: 1 });- Always uses
POST - Automatically sets
Content-Type: application/json - Merges custom
fetchoptions - Sends
dataas JSON (if provided) - Reads response as text first
- Parses JSON when possible
- Falls back to raw text
- Non-OK responses throw the response body (text) if available
- Network or parsing failures throw string errors
- No wrapped error objects
- No silent failures
You either get a value or a thrown error.
Thin wrapper around EventSource.
import { sse } from "@papack/client";
const events = sse("/api/events");
events.onmessage = (e) => {
console.log(e.data);
};