createUseApiMutation
función Desde 1.2.0
Crea useApiMutation para los endpoints POST, PUT, PATCH y DELETE de un manifiesto
público, como hacen los clientes generados.
ts
import { createUseApiMutation } from "@meekojs/meeko/framework";Código fuente src/app/composables/resources/use-api-mutation.ts:28
Firma #
ts
function createUseApiMutation<Contract extends Record<string, Record<string, AnyApiOperation>>, Manifest extends Pick<PublicServerManifest, "api">>(manifest: Manifest, options?: ClientOptions): UseApiMutation<ApiMutationContract<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 #
-
UseApiMutation<ApiMutationContract<Manifest, Contract>> El composable
useApiMutation. Con una ruta o un método sin endpoint, o conGET, lanzaTypeError, y fuera del script de un componente,Error.
Ejemplo #
ts
import { createBrowserClientOptions, createUseApiMutation } from "@meekojs/meeko/framework";
import type { ApiContract } from "../types/server-contracts.js";
const manifest = { version: 1, api: [{ clientKey: "notes", pathname: "/api/notes", method: "POST" }], rpc: [] } as const;
export const useApiMutation = createUseApiMutation<ApiContract, typeof manifest>(manifest, createBrowserClientOptions());Véase también #
- Mutaciones Framework full-stack