0.0.16 • Published 8 months ago

@metafar/api v0.0.16

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

how to install

yarn add @tanstack/react-query @metafar/api

create api.ts file with this content:

import { generateApi } from "@metafar/api";
import type { Middleware } from "openapi-fetch";
import { QueryClient } from "@tanstack/react-query";

// TODO: configure your session interceptor.
const sessionInterceptor: Middleware = {
  onRequest: (request) => {
    const farmaAccessToken = sessionStorage.getItem("accessToken") || "";
    const token = sessionStorage.getItem("token");
    if (token && farmaAccessToken) {
      request.request.headers.set("Authorization", `Bearer ${token}`);
      request.request.headers.set("farma-access-token", farmaAccessToken);
    }
  },
};

const api = generateApi({ baseUrl: window._env_.REACT_APP_C_BASE_URL }, [
  sessionInterceptor,
]);

export default api;
export const queryClient = new QueryClient();

add QueryClientProvider into your app root:

+ import { QueryClientProvider } from "@tanstack/react-query";
+ import { queryClient } from "src/api";

export const App = () => (
  <>
+   <QueryClientProvider client={queryClient}>
      <Routing />
+   </QueryClientProvider>
  </>
);

see more at https://openapi-ts.dev/openapi-react-query/

0.0.16

8 months ago

0.0.15

8 months ago

0.0.14

8 months ago

0.0.13

8 months ago

0.0.12

8 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago