arrow_back Back to Projects
php

Rest Api PHP

A lightweight, containerized PHP REST API built with Docker and MySQL that demonstrates clean MVC architecture for CRUD operations. Features a table-agnostic controller design, containerized development environment, and straightforward endpoint structure. Perfect for developers who want to understand PHP API fundamentals, learn Docker containerization, or need a simple foundation for building scalable REST services with minimal setup.

Timeline

2024

Links

deployed_code

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

  1. Database Layer (app/config/Database.php) manages PDO connections with Docker networking
  2. Controller Layer (app/controller/Controller.php) provides table-agnostic CRUD operations
  3. Endpoint Layer (app/api/*.php) contains individual API endpoints with direct execution
  4. Bootstrap Layer (app/bootstrap.php) initializes PSR-4 autoloading for class management
  5. Entry Point (app/index.php) serves as placeholder for future central routing

Technical Stack

code php
code mysql