cryogenic22's picture
Create services/api.ts
9205fca verified
const API_BASE_URL = process.env.REACT_APP_API_URL || 'http://localhost:8000';
export const api = {
chat: async (message: string, topic?: string) => {
const response = await fetch(`${API_BASE_URL}/api/chat`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message, topic }),
});
return response.json();
},
executeCode: async (code: string) => {
const response = await fetch(`${API_BASE_URL}/api/execute-code`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ code }),
});
return response.json();
},
getLearningPaths: async () => {
const response = await fetch(`${API_BASE_URL}/api/learning-paths`);
return response.json();
},
updateProgress: async (userId: string, moduleId: string) => {
const response = await fetch(`${API_BASE_URL}/api/update-progress`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ userId, moduleId }),
});
return response.json();
},
};
export default api;