File size: 779 Bytes
6dd9bad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001';

export async function apiRequest<T = any>(endpoint: string, options: RequestInit = {}): Promise<T> {
    const res = await fetch(`${API_URL}${endpoint}`, {
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers,
        },
    });

    if (!res.ok) {
        const errorData = await res.json().catch(() => ({}));
        const error = new Error(errorData.error || 'Une erreur est survenue');
        (error as any).status = res.status;
        throw error;
    }

    return res.json();
}

export const apiClient = {
    getStudent: (phone: string) => apiRequest(`/v1/student/me?phone=${phone}`),
    // Future endpoints can be added here
};