export default async function fetchApi({
endpoint,
query,
wrappedByKey,
wrappedByList,
page,
}) {
if (endpoint.startsWith(“/”)) {
endpoint = endpoint.slice(1);
}
}
const url = new URL(${import.meta.env.STRAPI_URL}/${endpoint}
);
if (query) {
Object.keys(query).forEach((key) => url.searchParams.append(key, query[key]));
}
if (page) {
url.searchParams.append(populate[${page}] [populate]
, “");
} else {
url.searchParams.append(“populate”, "”);
}
if (wrappedByKey) {
data = data[wrappedByKey];
}
if (wrappedByList) {
data = data[wrappedByList];
}
if (page) {
data = data[0][“attributes”][page];
return data;
}
This topic has been created from a Discord post (1295682701751222292) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord