UNPKG

@kubb/plugin-client

Version:

API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.

37 lines (35 loc) 969 B
import { t as __name } from "../chunk-DKWOrOAv.js"; import axios from "axios"; //#region src/clients/axios.ts let _config = { baseURL: typeof AXIOS_BASE !== "undefined" ? AXIOS_BASE : void 0, headers: typeof AXIOS_HEADERS !== "undefined" ? JSON.parse(AXIOS_HEADERS) : void 0 }; const getConfig = () => _config; const setConfig = (config) => { _config = config; return getConfig(); }; const mergeConfig = (...configs) => { return configs.reduce((merged, config) => { return { ...merged, ...config, headers: { ...merged.headers, ...config.headers } }; }, {}); }; const axiosInstance = axios.create(getConfig()); const client = async (config) => { return axiosInstance.request(mergeConfig(getConfig(), config)).catch((e) => { throw e; }); }; client.getConfig = getConfig; client.setConfig = setConfig; //#endregion export { axiosInstance, client, client as default, getConfig, mergeConfig, setConfig }; //# sourceMappingURL=axios.js.map