Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

Not translated yet

This page has not been translated into English yet, so it is shown in Spanish.

ApiClient

tipo

Cliente de API tipado: un árbol según clientKey con un método por verbo HTTP. Un segmento dinámico se llama con sus parámetros (api.users({ id }).get()); los métodos que se alcanzan así ya no reciben params. Cada método recibe query, body y signal según su operación y devuelve la salida, o rechaza con ClientError.

El segmento de clientKey que forma by con el nombre en mayúscula inicial de un parámetro de la ruta (byId para [id] o [...id]) es el segmento dinámico de ese parámetro. Desde 1.2, la forma api.users.byId.get({ params: { id } }) sigue funcionando pero está obsoleta y se retirará en 2.0.

ts
import type { ApiClient } from "@meekojs/meeko/framework";

Source code src/shared/clients.ts:261

Declaración #

ts
type ApiClient<Contract extends Record<string, Record<string, AnyApiOperation>>> = ApiNode<ClientEntries<Contract>, never>

Type parameters #

Contract extends Record<string, Record<string, AnyApiOperation>>

Contrato ApiContract generado, indexado por clientKey.

Example #

ts
import type { ApiClient, ApiOperation } from "@meekojs/meeko/framework";

declare const api: ApiClient<{ users: { get: ApiOperation<undefined, { page?: string }, undefined, string[]> } }>;
const names = await api.users.get({ query: { page: "2" } });

Segmentos dinámicos, desde 1.2:

ts
import type { ApiClient, ApiOperation } from "@meekojs/meeko/framework";

type User = { id: string; name: string };
declare const api: ApiClient<{
  "users.byId": { get: ApiOperation<{ id: string }, undefined, undefined, User> };
  "orgs.byOrg.users.byId": { delete: ApiOperation<{ org: string; id: string }, undefined, undefined, undefined> };
}>;
const user = await api.users({ id: "123" }).get();
await api.orgs({ org: "acme" }).users({ id: "123" }).delete();

See also #

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: packages/meeko/src/shared/clients.ts