Getting Started
Universal Client is a flexible and extensible client library for web applications supporting multiple transport protocols (HTTP, WebSocket, Server-Sent Events) inspired by @ngrx/signals syntax.
Installation
bash
npm install universal-clientbash
yarn add universal-clientbash
pnpm add universal-clientbash
bun add universal-clientbash
deno add @kevinbonnoron/universal-clientNote: On JSR, the package is published as
@kevinbonnoron/universal-client(scoped), but on npm it'suniversal-client(unscoped).
Quick Start
ts
import { universalClient, withFetchDelegate, withMethods } from 'universal-client';
const client = universalClient(
withFetchDelegate('https://jsonplaceholder.typicode.com'),
// withBetterFetchDelegate('https://jsonplaceholder.typicode.com'),
// withAxiosDelegate('https://jsonplaceholder.typicode.com'),
withMethods(({ delegate }) => ({
getUser: (id: string) => delegate.get(`/users/${id}`),
})),
);
const user = await client.getUser('1');
console.log(user);Features
- Multi-Protocol - HTTP, WebSocket, and SSE support
- Feature Composition - Build clients by composing features
- Tree-Shakeable - Only bundle what you use
- Fully Typed - Complete TypeScript support
- Delegate Pattern - Choose between fetch (default), axios, or better-fetch
- Lazy Loading - HTTP and SSE delegates are loaded lazily
Next Steps
- Basic Usage - HTTP requests, CRUD operations, error handling
- Interceptors - Transform requests/responses, add auth
- WebSocket - Real-time communication
- Server-Sent Events - Receiving real-time updates
- Advanced Features - Telemetry, environments, hooks, offline support