createUseApi
función Desde 1.1.0
Crea useApi para los endpoints GET de un manifiesto público. Los clientes generados
(.meeko/generated/clients.*.ts) lo exportan así; un host propio puede hacer lo mismo.
ts
import { createUseApi } from "@meekojs/meeko/framework";Código fuente src/app/composables/resources/use-api.ts:26
Firma #
ts
function createUseApi<Contract extends Record<string, Record<string, AnyApiOperation>>, Manifest extends Pick<PublicServerManifest, "api">>(manifest: Manifest, options?: ClientOptions): UseApi<ApiQueryContract<Manifest, Contract>>Parámetros de tipo #
-
Contractextends Record<string, Record<string, AnyApiOperation>> -
Manifestextends Pick<PublicServerManifest, 'api'>
Parámetros #
-
manifestManifest Manifiesto público con la lista
api.-
optionsClientOptionsopcional Opciones de transporte:
fetch,baseUrl, cabeceras y CSRF.
Devuelve #
-
UseApi<ApiQueryContract<Manifest, Contract>> El composable
useApi. Al llamarlo con una ruta sin endpoint GET lanzaTypeError, y fuera del script de un componente,Error.
Ejemplo #
ts
import { createBrowserClientOptions, createUseApi } from "@meekojs/meeko/framework";
import type { ApiContract } from "../types/server-contracts.js";
const manifest = { version: 1, api: [{ clientKey: "users", pathname: "/api/users", method: "GET" }], rpc: [] } as const;
export const useApi = createUseApi<ApiContract, typeof manifest>(manifest, createBrowserClientOptions());Véase también #
- load o composables Framework full-stack