You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
551 B

  1. import { create } from "apisauce";
  2. import { useCallback } from "react";
  3. import cache from "../utility/cache";
  4. const apiClient = create({
  5. baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/api",
  6. });
  7. const get = apiClient.get;
  8. apiClient.get = async (url, params, axiosConfig) => {
  9. const response = await get(url, params, axiosConfig);
  10. if (response.ok) {
  11. cache.store(url, response.data)
  12. return response;
  13. }
  14. const data = JSON.parse( await cache.get(url));
  15. return data ? {ok:true, data} : undefined;
  16. };
  17. export default apiClient;