I am calling a backend API to get a product in my frontend React application using async/await axios. For this call I defined a function as below:
export const getProduct = ():Promise<Product> => {
const {data} = await axios.get<Product>('http://myurl.com/api/getproduct');
return data;
}
Alternatively I can use the code below to return everything returned by get,
export const getProduct = ():Promise<AxiosResponse<Product>> => {
return axios.get<Product>('http://myurl.com/api/getproduct');
}
I was wondering if there is any best practice recommendation for choosing one over another.
AxiosResponse? What if you replaceaxioswith Javascript'sfetch? Should all clients change as well?getProductsshould know anything about how it's loaded. What if you decide to load cache it and load it from session storage?