@kubb/plugin-client
Version:
API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.
44 lines (42 loc) • 1.23 kB
JavaScript
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
const require_chunk = require('../chunk-CNbaEX1y.cjs');
let axios = require("axios");
axios = require_chunk.__toESM(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.default.create(getConfig());
const client = async (config) => {
return axiosInstance.request(mergeConfig(getConfig(), config)).catch((e) => {
throw e;
});
};
client.getConfig = getConfig;
client.setConfig = setConfig;
//#endregion
exports.axiosInstance = axiosInstance;
exports.client = client;
exports.default = client;
exports.getConfig = getConfig;
exports.mergeConfig = mergeConfig;
exports.setConfig = setConfig;
//# sourceMappingURL=axios.cjs.map