Skip to content

dynamicClient

dynamicClient<T>(params?): Client<T>

The dynamicClient function is a TypeScript function that creates a dynamic client for making API calls based on a provided endpoint and configuration.

Type parameters

T

The type describes Services. We have to import it from the server-side code. It’s valid import, because it’s not a value

Parameters

params?: ClientParams

The params parameter is an optional object that can contain two properties. endpoint - is a path for endpoint that handles JSON-RPC calls with POST method

Returns

Client<T>

The function dynamicClient returns an instance of Client<T>.

Example

// +server.ts
export type Client = typeof composer.clientType
// +page.svelte
// client and dynamicClient are the same
import { dynamicClient } from '@chord-ts/rpc/client';
import type { Client } from './+server';
const rpc = client<Client>({ endpoint: '/<path to endpoint>' });

Source

client.ts:181