title: How can I include response data to axios response?
body: <p>I try to work with Axios interceptors. The problem I'm facing is that I can't show the response I got from the API with Axios or even if it does, it shows constant data.</p>
  <pre><code>axios.defaults.baseURL = 'https://localhost:5001/api/';
  axios.defaults.withCredentials = true;
  
  const responseBody = res =&gt; res.data;
  
  axios.interceptors.response.use(async response =&gt; {
      const pagination = response.headers[&quot;x-pagination&quot;];
      if (pagination) {
          const parsed = JSON.parse(pagination);
          let metaData = {
              currentPage: parsed.currentPage,
              pageSize: parsed.pageSize,
              totalPages: parsed.totalPages,
              totalCount: parsed.totalCount
          };
          response.data = {
              metaData,
              data: response.data //I want to change this data
               // For example there is an endpoint named getAll and it returns all object
              //  Also there is a get endpoint and it returns a single object  
             //   But the problem is axios always return getAll endpoint's data.
  
          };
          return response;
      }
  }, error =&gt; {
      return Promise.reject(error);
  });
  </code></pre>
  <p>This is my request object</p>
  <pre><code>const requests = {
      get: (url, params) =&gt; axios.get(url, {params}).then(responseBody),
      post: (url, data) =&gt; axios.post(url, data).then(responseBody),
      put: (url, data) =&gt; axios.put(url, data).then(responseBody),
      delete: (url) =&gt; axios.delete(url).then(responseBody),
      postForm: (url, data) =&gt; axios.post(url, data, {
          headers: {
              'Content-Type': 'multipart/form-data'
          }
      }).then(responseBody),
      putForm: (url, data) =&gt; axios.put(url, data, {
          headers: {
              'Content-Type': 'multipart/form-data'
          }
      }).then(responseBody)
  };
  </code></pre>
  <p>and this is my API endpoints</p>
  <pre><code>const Endpoints = {
      getAll: () =&gt; requests.get('Endpoint'),
      get: (id) =&gt; requests.get(`Endpoint/${id}`),
      create: (data) =&gt; requests.postForm('Endpoint', data),
      update: (id, data) =&gt; requests.putForm(`Endpoint/${id}`, data),
      delete: (id) =&gt; requests.delete(`Endpoint/${id}`),
  }
  </code></pre>
  <p>What am I missing? Also, I use Redux Slice. If you want I can also send the redux code I write.</p>