This project is a simple RESTful API for managing emails using PHP and PostgreSQL. It includes endpoints to create, list, show, and delete emails. The project follows the PSR-12 coding standard and uses a simple routing mechanism.
- Create Email
- List Emails
- Show Email by ID
- Delete Email
- Send Email on Creation
-
Clone the repository:
git clone https://github.com/enjun06/46ccc13fd7a3065e4063b1d27d8a33d0.git
-
Navigate to the project directory:
cd 46ccc13fd7a3065e4063b1d27d8a33d0
-
Install dependencies:
composer install
-
Set up the database:
- Create a PostgreSQL database.
- Update the
.env
file with your database credentials.
-
Run the migration:
php database/migrations/create_emails_table.php
-
Start the PHP built-in server:
php -S localhost:8000 -t public
- Healthy Check:
GET /api
- List Emails:
GET /api/mail
- Show Email by ID:
GET /api/mail/{id}
- Create Email:
POST /api/mail
- Delete Email:
DELETE /api/mail/{id}
The system is designed as a simple RESTful API using PHP and PostgreSQL. It follows a layered architecture with controllers, models, and a router.
- Controller: Handles incoming HTTP requests and returns responses. Validates inputs and interacts with models.
- Model: Represents the data and business logic. Uses Eloquent ORM to interact with the PostgreSQL database.
- Router: Routes incoming requests to the appropriate controller actions based on the HTTP method and URI.
- Validator: Validates incoming request data against defined rules using the
illuminate/validation
package.
+-----------------+ +-----------------+ +-----------------+
| | | | | |
| HTTP Client +------>+ Router +------>+ Controller |
| | | | | |
+--------+--------+ +--------+--------+ +--------+--------+
^ | |
| v |
| +-------+-------+ |
| | | |
| | Validator | |
| | | |
| +-------+-------+ |
| | |
| v |
| +-------+-------+ |
| | | |
| | Model +<----------------+
| | |
| +-------+-------+
| |
v v
+--------+--------+ +--------+--------+
| | | |
| PostgreSQL DB | | Response (JSON)|
| | | |
+-----------------+ +-----------------+