A RESTful API for managing student records, built with Express.js and MySQL.
This project demonstrates CRUD operations, routing, controllers, and testing with Postman.
Extended activity includes an additional courses
resource with full CRUD.
- Full CRUD (Create, Read, Update, Delete) for students
- RESTful routes & controller structure
- MySQL integration using
mysql2
- Environment configuration via
.env
- CORS enabled for frontend access
- Tested with Postman
- Supplemental:
courses
table with full CRUD
-
Clone & install dependencies
git clone <repo-url> cd lab-crud-api npm install
-
Create .env file: DB_HOST=localhost DB_USER=root DB_PASS= DB_NAME=lab_crud PORT=3000
-
Create database and tables:
CREATE DATABASE lab_crud;
CREATE TABLE students ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, email VARCHAR(100) NOT NULL, course VARCHAR(50), year_level INT );
CREATE TABLE courses ( id INT AUTO_INCREMENT PRIMARY KEY, code VARCHAR(50) UNIQUE NOT NULL, title VARCHAR(100), units INT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
- Run server npm run dev
API Endpoints Students
-
GET /api/students → List all students
-
GET /api/students/:id → Get student by ID
-
POST /api/students → Create new student
-
PUT /api/students/:id → Update student
-
DELETE /api/students/:id → Delete student
Courses (Supplemental)
-
GET /api/courses → List all courses
-
GET /api/courses/:id → Get course by ID
-
POST /api/courses → Create new course
-
PUT /api/courses/:id → Update course
-
DELETE /api/courses/:id → Delete course