Axios instance in strapi

integration guide please,
In which directory we should create axios instance and how to import

axios instance will be depricated in v5 use useFetchClient instead

2 Likes

@Boegie19 , Can i use it in controller and services of content type folder ?

useFetchClient is for the frontend part

@Boegie19 what im doing is this , im populating strapi content type with external data also im making patch call on save of content item , for that im using fetch , but i want to use axios to do that, with axios instance

async patchProductOffering(productsToUpdate) {
    const baseUrl = process.env.POD_BASE_URL;
    const url = new URL(baseUrl + "products/1");

    try {
      const { title, description, thumbnail, productId } = productsToUpdate;

      const data = {
          id:'123'
      };

      let response = await axios.patch(url + productId, data);

      if (response.status == 200) {
        return { status: response.status };
      }
    } catch (error) {
      throw new Error(error.message);
    }
  }