@kubb/plugin-client
Version:
API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.
33 lines (31 loc) • 841 B
JavaScript
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 axiosInstance = axios.create(getConfig());
const client = async (config) => {
const globalConfig = getConfig();
return axiosInstance.request({
...globalConfig,
...config,
headers: {
...globalConfig.headers,
...config.headers
}
}).catch((e) => {
throw e;
});
};
client.getConfig = getConfig;
client.setConfig = setConfig;
var axios_default = client;
//#endregion
export { axiosInstance, client, axios_default as default, getConfig, setConfig };
//# sourceMappingURL=axios.js.map