@zenstackhq/fetch-client
v3.9.0
Published
Simple fetch-based client for consuming ZenStack's RPC-style CRUD API
Downloads
5,709
Readme
@zenstackhq/fetch-client
A lightweight, type-safe fetch-based client for consuming ZenStack's RPC-style auto CRUD API. Provides the same model and operation surface as the server-side ZenStackClient, but issues HTTP requests instead of running queries locally.
Installation
npm install @zenstackhq/fetch-clientUsage
import { createClient } from '@zenstackhq/fetch-client';
import { schema } from './schema';
const client = createClient(schema, {
endpoint: 'https://example.com/api/model',
});
const users = await client.user.findMany({ where: { active: true } });
const post = await client.post.create({ data: { title: 'Hello' } });
const [user, newPost] = await client.$transaction([
{ model: 'User', op: 'create', args: { data: { email: '[email protected]' } } },
{ model: 'Post', op: 'create', args: { data: { title: 'Hello' } } },
]);