ProjectTemplate/services/frontend/composables/useAPI.ts

19 lines
376 B
TypeScript
Raw Permalink Normal View History

2025-02-11 20:05:09 +01:00
import type { UseFetchOptions } from "nuxt/app";
export function useAPI<T>(
endpoint: string,
options?: UseFetchOptions<T>,
) {
if (!endpoint.startsWith("/")) {
endpoint = `/${endpoint}`
}
const cfg = useRuntimeConfig()
const fullUrl = `${cfg.public.backendUrl}${endpoint}`
return useFetch(
fullUrl,
{...options}
)
}