A two-part project demonstrating API integration with a PHP front end:
- Apiturismo — a custom REST API (PHP + MySQL) for managing a
clientsdatabase (CRUD). - Frontangular — a PHP storefront that consumes the Fake Store API to display products.
Api-Integration-with-Front-End/
├── Apiturismo/ # Custom REST API (PHP + MySQLi)
│ ├── conexion.php # Database connection
│ ├── getcliente.php # GET /getcliente → list or fetch client(s)
│ ├── save.php # POST /save → create client
│ ├── update.php # PUT /update → update client
│ └── delete.php # DELETE /delete → remove client
│
└── Frontangular/ # PHP storefront (Fake Store API)
├── index.php # Home — random featured product
├── listado.php # Product listing table
└── detalle.php # Product detail page
Create a MySQL database named turismo and run the following SQL:
CREATE DATABASE turismo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE turismo;
CREATE TABLE clientes (
id INT AUTO_INCREMENT PRIMARY KEY,
nombres VARCHAR(100) NOT NULL,
apellidos VARCHAR(100) NOT NULL,
direccion VARCHAR(200),
telefono VARCHAR(20),
correo VARCHAR(100),
created DATETIME,
modified DATETIME
);Then update conexion.php with your credentials if needed.
Base URL: http://localhost/Apiturismo/
| Method | File | Description | Body (JSON) |
|---|---|---|---|
GET |
getcliente.php |
Get all clients | (none) |
GET |
getcliente.php |
Get client by ID | { "id": 1 } |
POST |
save.php |
Create a new client | { "nombres": "...", "apellidos": "...", "direccion": "...", "telefono": "...", "correo": "..." } |
PUT |
update.php |
Update existing client | { "id": 1, "nombres": "...", ... } |
DELETE |
delete.php |
Delete a client | { "id": 1 } |
GET all clients
[
{ "id": "1", "nombres": "John", "apellidos": "Doe", "correo": "john@example.com" }
]POST / PUT / DELETE
{ "codigo": "ok", "mensaje": "Record saved" }Requires a PHP server with allow_url_fopen enabled (to call the Fake Store API).
| Page | URL | Description |
|---|---|---|
| Home | index.php |
Random featured product of the day |
| Product list | listado.php |
Full product table with detail links |
| Product detail | detalle.php?id={id} |
Full details for a single product |
- Clone or extract the project into your server's web root (e.g.
htdocs/on XAMPP). - Create the
turismodatabase using the SQL above. - Open
Apiturismo/conexion.phpand set your DB credentials. - Visit
http://localhost/Frontangular/index.phpto see the storefront. - Test the API with Postman or
curl.
# Get all clients
curl http://localhost/Apiturismo/getcliente.php
# Create a client
curl -X POST http://localhost/Apiturismo/save.php \
-H "Content-Type: application/json" \
-d '{"nombres":"John","apellidos":"Doe","direccion":"123 Main St","telefono":"555-1234","correo":"john@example.com"}'
# Delete a client
curl -X DELETE http://localhost/Apiturismo/delete.php \
-H "Content-Type: application/json" \
-d '{"id":1}'This project is intended for learning purposes. Before deploying to production:
- Use prepared statements for all queries (save/update already do — apply the same pattern to
getcliente.phpanddelete.php). - Replace
Access-Control-Allow-Origin: *with a specific domain. - Store DB credentials in environment variables, not in source files.
- Add input validation and authentication (e.g. API keys or JWT).
This project is open source and available under the MIT License.