It has a database and a server-side PHP application to provide a REST API functionality to clients written in PHP, Bash, Python, Node, HTML forms and HTML/JavaScript.
For a version of a similar implementation with authentication, please refer to this project.
This system simulates the registering of persons on a database.
The following diagram shows all the clients on top and the server-side application on the bottom part.
REST API Architecture diagram
The server is composed of four parts:
- FrontController: implemented in the index.php, it validates the request. Then, the FrontController processes it by calling the
PersonController
'sprocessRequest
method. - DatabaseConnector: implemented in DatabaseConnector.php and called by bootstrap.php, which will be imported (required) by index.php, it opens the connection to the database. The database parameters are located in the .env local file, and are loaded by phpdotenv.
- PersonController: implemented in PersonController.php, it instantiates the
PersonGateway
to handle the database processes. It also implements the method verification, data validation/sanitization. Depending on the HTTP method a different method fromPersonGateway
is invoked. - PersonGateway: implemented in PersonGateway.php, it is the "model" that handles database activities. It implements the methods with PDO prepare to protect the database from SQL injection.
- Be sure to have PHP installed.
- Clone this repository, enter in the root folder and run
php -S 127.0.0.1:8000 -t public
(it can be run as well with any Web server, or in the background by forking with&
ornohup
).