mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2025-05-30 07:13:12 +00:00
16 lines
464 B
TypeScript
16 lines
464 B
TypeScript
import { type Item, type JSONResponse } from "./types";
|
|
|
|
const API_URL = "http://127.0.0.1:8080";
|
|
|
|
export async function getPopularToday(): Promise<Item[]> {
|
|
const response = await fetch(`${API_URL}/api/items`);
|
|
const {data, error}: JSONResponse = await response.json();
|
|
|
|
if (response.ok) {
|
|
if (data?.item) {
|
|
return data?.item;
|
|
}
|
|
throw new Error("Failed to fetch popular today");
|
|
}
|
|
throw new Error(error);
|
|
}
|