--- jd-id: "01.01" name: "src-api" desc: "REST client layer for the Django backend. Centralizes the axios instance with the JWT refresh interceptor and exposes one service module per resource domain." author: "Clark Lin" updateTime: "2026-07-06" status: active type: "A-高层系统" tags: - Service - axios - REST - JWT --- ## Core Files | File path | Role | |-----------|------| | `src/api/index.js` | Shared axios `apiClient` (`baseURL: http://192.168.1.52:8001`, `timeout: 30s`, JSON headers) and the `apiEndpoints` table (currently stale for `terms`, missing for `task`/`story`) | | `src/api/authService.js` | `login()`, `refreshAccessToken()` — wraps `/api/token/` and `/api/token/refresh/` | | `src/api/studentService.js` | CRUD for `/api/students/`; ships a `fetchAllPages()` helper that loops `page_size: 100` with a 100-page safety cap | | `src/api/subjectService.js` | CRUD for `/api/subjects/` | | `src/api/termService.js` | CRUD for `/api/terms/` | | `src/api/storyService.js` | CRUD for `/api/stories/` (paths hardcoded; not present in `apiEndpoints`) | | `src/api/taskService.js` | CRUD for tasks, including `getTaskImage(id)` which fetches images as `blob` with `Accept: */*` to avoid 406s; duplicates the `fetchAllPages()` helper verbatim from `studentService.js` | | `src/api/README.md` | Working notes for the service layer | --- ## Conventions - Plain JS modules exporting `async` functions that return `response.data`. - Service functions log heavily to `console` (including sample data) when called. - Base64 payloads are redacted in `studentService` — mirror that pattern when adding endpoints that return images/audio. - DRF pagination responses (`{ count, next, previous, results }`) are normalized via the duplicated `fetchAllPages()` helper — if pagination logic changes, **update both** `studentService.js` and `taskService.js` (or factor it out). --- Home: [[01.00 student-app-frontend]] | **Location:** `C:\Projects\vue\student-app-frontend\src\api`