UNPKG

nuxt-procedures

Version:

Nuxt module to define and easily consume your backend API in a validated and type-safe way using procedures and Zod schemas.

24 lines (23 loc) 656 B
import superjson from "superjson"; import { useFetch, useRequestHeaders } from "#imports"; export function createCaller(url) { return { call: (input) => { return $fetch("/api" + url, { method: "POST", body: superjson.serialize(input), parseResponse: superjson.parse, headers: useRequestHeaders(["cookie"]) }); }, useCall: (input) => { return useFetch("/api" + url, { key: `${url}: ${JSON.stringify(input)}`, method: "POST", body: superjson.serialize(input), parseResponse: superjson.parse, headers: useRequestHeaders(["cookie"]) }); } }; }