All checks were successful
Publish Docker Images / build-and-publish (push) Successful in 10m25s
38 lines
799 B
TypeScript
38 lines
799 B
TypeScript
export function useApi() {
|
|
const config = useRuntimeConfig();
|
|
const backend = config.public.apiBase;
|
|
const commonBaseOptions = { baseURL: backend };
|
|
|
|
const get = (endpoint, options = {}) =>
|
|
useFetch(endpoint, {
|
|
method: 'GET',
|
|
...commonBaseOptions,
|
|
...options,
|
|
});
|
|
|
|
const post = (endpoint, body, options = {}) =>
|
|
$fetch(endpoint, {
|
|
method: 'POST',
|
|
body,
|
|
...commonBaseOptions,
|
|
...options,
|
|
});
|
|
|
|
const put = (endpoint, body, options = {}) =>
|
|
$fetch(endpoint, {
|
|
body,
|
|
method: 'PUT',
|
|
...commonBaseOptions,
|
|
...options,
|
|
});
|
|
|
|
const del = (endpoint, options = {}) =>
|
|
$fetch(endpoint, {
|
|
method: 'DELETE',
|
|
...commonBaseOptions,
|
|
...options,
|
|
});
|
|
|
|
return { get, post, put, del };
|
|
}
|