Test out API requests from frontend to backend

This commit is contained in:
Michał Gdula 2024-04-27 17:15:13 +01:00
parent 53cbe6e26c
commit 8416549858
5 changed files with 87 additions and 6 deletions

29
front/src/lib/api.js Normal file
View file

@ -0,0 +1,29 @@
import Items from '%/lib/testData.js';
export async function getPopularToday() {
const res = await fetch("/api/items")
const data = res.json()
if (res.ok) {
return data
} else {
throw new Error("Failed to fetch popular today")
}
}
export function getMenuItems() {
return [
{
name: "Main Menu",
items: Items,
},
{
name: "Breakfast",
items: [],
},
{
name: "Seasonal",
items: Items,
},
];
}