← Projects — CIS 266
Unit2_Ex3
A PHP REST API service provider and jQuery AJAX client demonstrating a two-tier web service architecture backed by a MySQL database, with a custom cyberpunk-themed UI.
Overview
This project implements a RESTful web service architecture divided into a Service Provider and a Service Client. The provider exposes two PHP API endpoints that query a MySQL students database and return JSON responses — one listing available tables and one returning all records from a specified table. A separate HTML/jQuery client consumes these endpoints asynchronously via AJAX, rendering results to the page without a full reload. All database access is encapsulated in a reusable StudentsDB_Access OOP class.
Features
terb_Tables_API.php— REST endpoint returning a JSON-encoded list of database tablesterb_Records_API.php— REST endpoint accepting atableNameparameter and returning all matching records as JSONStudentsDB_AccessOOP class encapsulating all MySQL operations (showDatabases,showTables,displayRecords,selectOne)- jQuery AJAX client (
terb_Records_Client.html) consuming the Records API and rendering results dynamically - jQuery AJAX client (
terb_Tables_Client.html) consuming the Tables API without a page reload - Standalone API tester pages for direct browser-based endpoint testing
- Single-record lookup view (
DisplayOne.html+terb_displayOneRecord_OOP.php) using POST by ID - Cyberpunk-themed CSS UI with neon glow effects applied across all views
Screenshots
Home Page
Database Output
Code Highlights
// ServiceProvider/terb_Records_API.php — REST endpoint returning JSON records
include('classes/StudentsDB_Access.php');
$studentsDB = new StudentsDB_Access();
// Accept table name from GET or POST request
$table = $_REQUEST['tableName'];
// Query the database via the OOP class
$DB_Result = $studentsDB->displayRecords($table);
$data = array();
// Build associative array from result set
while ($row = $DB_Result->fetch_assoc()) {
$data[] = $row;
}
// Return data as JSON to the client
print(json_encode($data));
Challenges & Solutions
Challenge: Decoupling the client from direct database access while keeping the API stateless and simple.
Solution: All SQL logic is isolated inside the StudentsDB_Access class; the API endpoints instantiate the class, call a single method, and immediately serialize the result to JSON — keeping each endpoint to under 15 lines.
Challenge: Consuming the JSON response in the browser and displaying it without a page reload.
Solution: The HTML clients use jQuery’s $.ajax() with a .done() callback that iterates the returned data array and writes formatted output into a designated <span id="aMessage"> element, keeping the UI fully decoupled from the server response format.

