@tsuz/sdk
v0.2.0
Published
A minimal API client foundation for projects generated by Tsu templates.
Readme
@tsuz/sdk
A minimal API client foundation for projects generated by Tsu templates.
The SDK gives generated projects a typed request entry point from day one. It supports a real fetch path and a mock adapter path so templates can demonstrate request flows without depending on a backend service.
Install
pnpm add @tsuz/sdkUsage
import { createClient } from "@tsuz/sdk";
interface User {
id: number;
name: string;
}
const api = createClient({
baseUrl: "https://api.example.com"
});
const users = await api.get<User[]>("/users");Mock Adapter
import { createClient } from "@tsuz/sdk";
const api = createClient({
baseUrl: "https://example.tsu.local",
async adapter({ path }) {
if (path === "/users") {
return [{ id: 1, name: "Tsu" }];
}
throw new Error("Unknown mock path");
}
});
const users = await api.get<{ id: number; name: string }[]>("/users");API
| Export | Purpose |
| --- | --- |
| createClient(options) | Creates a typed client with get<T>() |
| SdkError | Error class for failed SDK requests |
| QuickStartSdk | Backward-compatible base URL helper |
In Tsu Templates
The Vue3 and React templates use createClient with a mock adapter in the generated dashboard starter page. Replace the adapter with your real API endpoint when connecting the app to a backend.
