FA
Farrassubahan/php-api-client-server-architecture
Refresh Belajar PHP membangun CRUD lewat API, tidak query langsung.
PHP API Client Architecture (Native)
A lightweight API-driven application built using Native PHP.
This project aims to teach PHP without a framework, demonstrating a clear separation between:
- API Server โ Handles database operations and returns JSON response
- Client App โ Consumes API via cURL and renders data in HTML views
The goal is to understand and implement RESTful API architecture,
cURL-based HTTP requests, and modular MVC structure without frameworks.
๐ฅ Features
๐ฅ Client App
- MVC-like structure (Controller, Views, CurlClient)
- Consume API via cURL (GET, POST, PUT, DELETE)
- Modal-based CRUD (Create, Read, Update, Delete)
- Clean route handling (
web.php?action=...) - Redirect, form request handling, and dynamic response
๐ API Server
- RESTful API in Native PHP
- JSON responses with HTTP status codes
- Endpoint-based structure (
users/index.php,users/create.php, etc.) - PDO-based database access
- Password hashing for secure user storage
๐ Project Structure
belajar-php-native/
โ
โโโ api-server/
โ โโโ config/
โ โ โโโ database.php
โ โโโ endpoints/
โ โโโ users/
โ โโโ index.php # GET all users
โ โโโ show.php # GET single user
โ โโโ create.php # POST - create user
โ โโโ update.php # PUT - update user
โ โโโ delete.php # DELETE - delete user
โ
โโโ client-app/
โ โโโ config/
โ โ โโโ api_config.php
โ โโโ controllers/
โ โ โโโ UsersController.php
โ โโโ core/
โ โ โโโ CurlClient.php # Handles cURL API Requests
โ โโโ views/
โ โ โโโ users/
โ โ โโโ index.php # Main UI (CRUD modal-based)
โ โ โโโ create.php # (optional)
โ โ โโโ edit.php # (optional)
โ โโโ routes/
โ โ โโโ web.php # Basic Routing
โ โโโ index.php # Entry point
โ
โโโ README.md
๐ Tech Stack
| Layer | Technology |
|---|---|
| Client Application | Native PHP, HTML, Modal-based UI |
| API Communication | PHP cURL |
| API Response Format | JSON (REST) |
| Database | MySQL (via PDO) |
| Server Stack | Apache (Laragon/XAMPP) |
โ๏ธ Installation & Setup
1๏ธโฃ Clone the Repository
git clone https://github.com/your-username/php-api-client-architecture.git
cd php-api-client-architecture2๏ธโฃ Configure API
api-server/config/database.php
$host = "localhost";
$db_name = "your_database";
$username = "root";
$password = "";3๏ธโฃ Configure Client API URL
client-app/config/api_config.php
define("API_BASE_URL", "http://localhost/belajar-php-native/api-server/endpoints/");4๏ธโฃ Ensure cURL is enabled in php.ini
extension=curlRestart Apache/Laragon after enabling.
๐ Usage
Run API
http://localhost/belajar-php-native/api-server/endpoints/users/index.php
Run Client Application
http://localhost/belajar-php-native/client-app/
Auto loads UsersController@index
Displays users table with modal-based CRUD
๐ง Future Enhancements
- ๐ Authentication with token-based login (JWT / OAuth)
- โ Server-side validation and error handling
- ๐ Pagination and search
- ๐ File upload via API (image/avatar)
- โ Migration to AJAX (Single Page API Client)
- ๐งฑ Refactor toward mini PHP MVC Framework
๐ License
MIT License. Free to use, modify, and improve.
๐ค Author
Muhammad Farras Subahan
Web Developer & API Learner
๐ Focus: Native PHP, API Architecture, Laravel, Next.js
"Frameworks come later. Foundation always comes first."