Rest Api PHP
The Brief
This project is a web service that allows applications to store, retrieve, and manage information about people through simple web requests. Think of it as a digital filing cabinet that can be accessed from anywhere on the internet. Instead of manually managing spreadsheets or databases, other applications can automatically add new people, update their information, or search through records using standardized web commands. The entire system runs in isolated containers, making it easy to deploy and maintain without worrying about server configuration conflicts.
Architecture & Technology Stack
This REST API showcases fundamental PHP development patterns using containerized infrastructure:
Backend Architecture
- Language: PHP 8.1 with Apache server for HTTP request handling
- Database: MySQL 8.0 with persistent data volumes for reliable storage
- Containerization: Docker Compose orchestrating multi-service environment
- Data Access: PDO with prepared statements for secure database operations
- API Design: Individual endpoint files following RESTful conventions
- Autoloading: PSR-4 compliant class loading with custom bootstrap
Infrastructure Components
- Docker Services: PHP-Apache container and MySQL container with networking
- Volume Management: Persistent database storage and live code mounting
- Port Mapping: HTTP (80) and MySQL (3306) exposed for development
- CORS Configuration: Manual header setting per endpoint for cross-origin requests
Key Features
- Table-Agnostic Controller: Generic CRUD operations that work with any table structure
- Containerized Development: Complete development environment with single command startup
- Direct Endpoint Access: Individual API files without complex routing overhead
- MVC Pattern: Separation of concerns with dedicated Controller and Database classes
- RESTful Design: Standard HTTP methods (GET, POST, PUT, DELETE) for resource manipulation
- Cross-Origin Support: CORS headers configured for frontend integration
API Architecture
- Database Layer (
app/config/Database.php) manages PDO connections with Docker networking - Controller Layer (
app/controller/Controller.php) provides table-agnostic CRUD operations - Endpoint Layer (
app/api/*.php) contains individual API endpoints with direct execution - Bootstrap Layer (
app/bootstrap.php) initializes PSR-4 autoloading for class management - Entry Point (
app/index.php) serves as placeholder for future central routing