Initial commit from your app

This commit is contained in:
Reynier Matthieu
2025-02-01 22:24:59 +01:00
parent 8eda5e8cfe
commit d4c44ece53
38 changed files with 9031 additions and 0 deletions

39
src/services/api.ts Normal file
View File

@@ -0,0 +1,39 @@
import { Card } from '../types';
const SCRYFALL_API = 'https://api.scryfall.com';
export const searchCards = async (query: string): Promise<Card[]> => {
const response = await fetch(`${SCRYFALL_API}/cards/search?q=${query}`);
const data = await response.json();
return data.data;
};
export const getRandomCards = async (count: number = 10): Promise<Card[]> => {
const cards: Card[] = [];
for (let i = 0; i < count; i++) {
const response = await fetch(`${SCRYFALL_API}/cards/random`);
const card = await response.json();
cards.push(card);
}
return cards;
};
export const getCardById = async (cardId: string): Promise<Card> => {
const response = await fetch(`${SCRYFALL_API}/cards/${cardId}`);
return await response.json();
};
export const getCardsByIds = async (cardIds: string[]): Promise<Card[]> => {
const response = await fetch(`${SCRYFALL_API}/cards/collection`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
identifiers: cardIds.map((id) => ({ id })),
}),
});
const data = await response.json();
return data.data;
};