get partial values axios typescript code example

Example 1: axios instance

// lets you create custom pre-configured fetch api call!
const getUser = axios.create({
  baseURL: 'https://randomuser.me/api/', // we define url
  timeout: 1000, // (optional) set timeout
  headers: {'X-Custom-Header': 'foobar'} // pass headers
});

// use later like this
getUser().then(response => console.log(response))

Example 2: javascript axios request with params for client side rendering

let params = {
      page: currentPage + 1,
      per_page: rowsPerPage
    }
    axios
      .get('/products', { params: params })
      .then((response) => {
        if (isMountedRef.current) {
          setProducts(response.data.data);
          setMeta(response.data.meta);
        }
      });