How daveh/php-rest-api works
This is a small PHP REST API for managing product records. A client requests the /products collection or an individual product; index.php routes the request to ProductController, which validates writes and handles list, read, create, update, and delete operations through ProductGateway. The gateway uses Database to connect to MySQL. The controller encodes JSON responses and sets relevant HTTP statuses. Error and exception handlers are registered at the entry point. README capabilities are reflected where supported by the sampled source; database schema details were not inspected.
Main entry points: ProductController.php Product controller · ProductGateway.php Product gateway · index.php HTTP entry point · Database.php Database connector
Components 7
API handling
- HTTP entry point
index.php - Error handlers
src/ErrorHandler.php
Product operations
- Product controller
src/ProductController.php
Persistence and errors
- Product gateway
src/ProductGateway.php - Database connector
src/Database.php
Other components
- API client
- MySQL database
Connections 16
- API client → HTTP entry point: sends HTTP request
- HTTP entry point → Product controller: dispatches request
- HTTP entry point → Error handlers: registers handlers
- HTTP entry point → Database connector: creates connector
- HTTP entry point → Product gateway: creates gateway
- HTTP entry point → Product controller: creates controller
- Product controller → Product gateway: reads product
- Product controller → Product gateway: lists products
- Product controller → Product gateway: creates product
- Product controller → Product gateway: updates product
- Product controller → Product gateway: deletes product
- Product gateway → Product controller: returns records
- Product gateway → Database connector: requests connection
- Database connector → MySQL database: opens PDO connection
- Product gateway → MySQL database: queries product data
- Product controller → API client: returns JSON response