I have featch data from external api – it’s work fine
"use server";
import axios from "axios";
export default async function getCategories() {
const options = {
method: "GET",
url: "https://XXX/api/admin/v3/products/categories",
headers: {
accept: "application/json",
"X-API-KEY":
"XYZ",
},
};
try {
const response = await axios.request(options);
console.log(response);
} catch (error) {
console.log(error);
}
}
a in console log we see a big object with respones:
{
status: 200,
statusText: 'OK',
headers: Object [AxiosHeaders] {
server: 'nginx',
date: 'Wed, 31 Jul 2024 07:07:22 GMT',
'content-type': 'application/json',
'content-length': '2849',
connection: 'keep-alive'
}
.....
data: {
categories: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
last_changed_time: '',
results_number_all: 10,
results_number_page: 1,
results_page: 0,
results_limit: 1000
}
And question is how to handle this data correct? what is good practice? in this specific situation and i can’t just fetch this in front-end because will be cors problems.