mirror of
https://github.com/ceratic/MediaCollectorLibaryFrontend.git
synced 2026-05-13 23:56:45 +02:00
2.9 KiB
2.9 KiB
API Integration Guide
This document explains how the React frontend integrates with the PHP backend API.
API Configuration
Environment Setup
- Copy
.env.exampleto.env:
cp .env.example .env
- Configure your API URL in
.env:
VITE_API_URL=http://localhost:8080/api
Available API Endpoints
Based on your backend routes, the following endpoints are available:
Authentication
POST /api/auth/login- User loginPOST /api/auth/register- User registrationPOST /api/auth/refresh- Refresh JWT tokenGET /api/auth/me- Get current user (protected)
Media
GET /api/movies- List movies with paginationGET /api/movies/{id}- Get single movieGET /api/tvshows- List TV shows with paginationGET /api/tvshows/{id}- Get single TV showGET /api/games- List games with paginationGET /api/games/{id}- Get single game
Search
GET /api/search?q={query}&type={type}- Search across media types
System
GET /api/status- API health check
API Service Structure
The frontend is organized with:
-
API Service (
src/services/api.ts)- Axios configuration with interceptors
- Authentication handling
- Endpoint methods
-
React Hooks (
src/hooks/useApi.ts)- React Query integration
- Custom hooks for each endpoint
- Caching and error handling
-
Updated Components
- Movies page now uses
useMovies()hook - Dashboard uses
useDashboardStats()anduseRecentActivity() - Search page uses
useSearch()hook
- Movies page now uses
Authentication Flow
- Login via
/api/auth/login - Store JWT token in localStorage
- Token automatically added to all requests
- Auto-logout on 401 responses
Pagination
All list endpoints support:
page- Page number (default: 1)per_page- Items per page (default: 20)search- Search termgenre- Filter by genreyear- Filter by year
Error Handling
- 401: Auto-redirect to login
- 404: Show "not found" message
- 500: Show generic error message
- Network: Show connection error
Next Steps
-
Complete Backend Endpoints: Your MediaController needs implementations for:
listMovies()methodgetMovie()method- Dashboard stats endpoint
- Recent activity endpoint
-
Add Missing Features:
- Music API endpoints
- Adult content API endpoints
- Actors/performers API endpoints
- CRUD operations (create, update, delete)
-
Testing:
- Test API connectivity
- Test authentication flow
- Test error handling
Example API Response Format
{
"success": true,
"data": {
"items": [...],
"pagination": {
"total": 100,
"per_page": 20,
"current_page": 1,
"last_page": 5
}
}
}
Development Notes
- The frontend includes fallback mock data
- API calls are made through React Query for caching
- All requests include JWT authentication headers
- CORS is configured for development