Pass in custom axios instance
Hey, first of all, this package seems really awesome and we currently have a very large manually maintained api package that has all of our typesafe code, which this package could completely make redundant, which would be a huge time saver!
I am struggling a bit with the docs here - If I wanted to have each of the endpoint-generated axios-functions to have a custom axios instance passed to it as a parameter, is that the job for a custom mutator?
What I am going for is something like this:
export const getPets = (axiosInstance: axiosInstance) => {
/**
* List all pets.
* @summary GET pets
*/
const petsIndex = <TData = AxiosResponse<PetsIndex200>>(
params?: PetsIndexParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axiosInstance.get(`/pets`, {
...options,
params: { ...params, ...options?.params },
});
};
}
where axiosInstance is something I can pass into the request
Thanks
@anymaniax I know I'm a bit late on this but the solution provided by @AleskiWeb is way better considering it doesn't involve instantiating a global variable for the axios instance. That way you can have multiple clients with different authorization token for example.