Skip to content

Pass in custom axios instance #653

@AleskiWeb

Description

@AleskiWeb

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

Metadata

Metadata

Assignees

Labels

axiosAxios related issuetanstack-queryTanStack Query related issue

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions