Spaces:
Runtime error
Runtime error
Download frontend/src/lib/api.ts from adwhytahumans/CRM_FastAPI_React: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/adwhytahumans/CRM_FastAPI_React/resolve/main/frontend/src/lib/api.ts
- Command line
-
hf download hf://spaces/adwhytahumans/CRM_FastAPI_React/frontend/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/adwhytahumans/CRM_FastAPI_React/resolve/main/frontend/src/lib/api.ts
1.87 kB
| import { LearnerIn, LearnerOut } from '@/types/learner'; | |
| const API_BASE_URL = 'http://localhost:8000'; | |
| const defaultHeaders = { | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/json', | |
| }; | |
| export async function createLearner(learner: LearnerIn): Promise<LearnerOut> { | |
| const response = await fetch(`${API_BASE_URL}/learners`, { | |
| method: 'POST', | |
| headers: defaultHeaders, | |
| body: JSON.stringify(learner), | |
| }); | |
| if (!response.ok) { | |
| throw new Error('Failed to create learner'); | |
| } | |
| return response.json(); | |
| } | |
| export async function getLearners(): Promise<LearnerOut[]> { | |
| try { | |
| console.log('Fetching learners from:', `${API_BASE_URL}/learners`); | |
| const response = await fetch(`${API_BASE_URL}/learners`, { | |
| headers: defaultHeaders, | |
| }); | |
| console.log('Response status:', response.status); | |
| if (!response.ok) { | |
| const errorText = await response.text(); | |
| console.error('Error response:', errorText); | |
| throw new Error(`Failed to fetch learners: ${response.status} ${errorText}`); | |
| } | |
| const data = await response.json(); | |
| console.log('Received data:', data); | |
| return data; | |
| } catch (error) { | |
| console.error('Error in getLearners:', error); | |
| throw error; | |
| } | |
| } | |
| export async function updateLearner(id: number, learner: LearnerIn): Promise<LearnerOut> { | |
| const response = await fetch(`${API_BASE_URL}/learners/${id}`, { | |
| method: 'PUT', | |
| headers: defaultHeaders, | |
| body: JSON.stringify(learner), | |
| }); | |
| if (!response.ok) { | |
| throw new Error('Failed to update learner'); | |
| } | |
| return response.json(); | |
| } | |
| export async function deleteLearner(id: number): Promise<void> { | |
| const response = await fetch(`${API_BASE_URL}/learners/${id}`, { | |
| method: 'DELETE', | |
| headers: defaultHeaders, | |
| }); | |
| if (!response.ok) { | |
| throw new Error('Failed to delete learner'); | |
| } | |
| } |