# 7. External APIs ## DofusDB API Integration **Base URL**: `https://api.dofusdb.fr` ### Endpoints Used | Endpoint | Purpose | |----------|---------| | `GET /classes` | Liste des classes de personnages | | `GET /servers` | Liste des serveurs | | `GET /quests` | Liste des quêtes | | `GET /dungeons` | Liste des donjons | | `GET /achievements` | Liste des succès | ### Integration Service ```typescript // src/lib/server/dofusdb.ts import NodeCache from 'node-cache'; const cache = new NodeCache({ stdTTL: 3600 }); // 1 hour cache const BASE_URL = 'https://api.dofusdb.fr'; interface DofusDbOptions { lang?: 'fr' | 'en'; limit?: number; } export async function fetchFromDofusDb( endpoint: string, options: DofusDbOptions = {} ): Promise { const { lang = 'fr', limit = 100 } = options; const cacheKey = `dofusdb:${endpoint}:${lang}:${limit}`; // Check cache const cached = cache.get(cacheKey); if (cached) return cached; // Fetch from API const url = new URL(endpoint, BASE_URL); url.searchParams.set('$lang', lang); url.searchParams.set('$limit', limit.toString()); const response = await fetch(url.toString(), { headers: { 'Accept': 'application/json' }, }); if (!response.ok) { throw new Error(`DofusDB API error: ${response.status}`); } const data = await response.json(); cache.set(cacheKey, data); return data as T; } // Specific fetchers export const getClasses = () => fetchFromDofusDb('/classes'); export const getServers = () => fetchFromDofusDb('/servers'); export const getQuests = () => fetchFromDofusDb('/quests'); export const getDungeons = () => fetchFromDofusDb('/dungeons'); ``` ---