Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide to use axios #248

Open
mrsafalpiya opened this issue Apr 29, 2024 · 1 comment
Open

Guide to use axios #248

mrsafalpiya opened this issue Apr 29, 2024 · 1 comment

Comments

@mrsafalpiya
Copy link

mrsafalpiya commented Apr 29, 2024

Hello. I understand that in order to use axios we have to modify the backendFetcher.ts file. But I do not want to miss anything and introduce a bug. Thus it would be great if there was an official guide to use axios with this awesome tool.

My attempt:

export async function backendFetch<
  TData,
  TError,
  TBody extends {} | FormData | undefined | null,
  THeaders extends {},
  TQueryParams extends {},
  TPathParams extends {},
>({
  url,
  method,
  body,
  headers,
  pathParams,
  queryParams,
  signal,
}: BackendFetcherOptions<
  TBody,
  THeaders,
  TQueryParams,
  TPathParams
>): Promise<TData> {
  // $axios is my axios instance with an interceptor
  const response = await $axios({
    url: `${baseUrl}${resolveUrl(url, queryParams, pathParams)}`,
    method: method.toUpperCase(),
    signal: signal,
    data: body
      ? body instanceof FormData
        ? body
        : JSON.stringify(body)
      : undefined,
    headers: { "Content-Type": "application/json", ...headers },
  });
  return response.data;
}
@dahchon
Copy link

dahchon commented May 11, 2024

same question. but before this is answered. there're many alternatives

https://github.com/7nohe/openapi-react-query-codegen

https://orval.dev/quick-start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants