Lesson 8 of 8Article22 min
Project: Build Course Enrollment API
Create a production-style backend service for course enrollment with users, courses, and enrollments resources. Include validation, auth middleware, and persistent storage integration.
Project scope
Create a production-style backend service for course enrollment with users, courses, and enrollments resources. Include validation, auth middleware, and persistent storage integration.
Milestone checklist
- Scaffold Express app with modular routes and controllers.
- Implement CRUD endpoints for users and courses.
- Create enrollment endpoint with duplicate-enrollment guard.
- Add pagination, filtering, and basic rate limiting.
- Write API tests for success and failure scenarios.
Enrollment route starter
app.post("/api/enrollments", async (req, res, next) => {
try {
const { userId, courseId } = req.body;
// 1) validate payload
// 2) ensure user and course exist
// 3) prevent duplicate enrollment
// 4) insert enrollment row/document
res.status(201).json({ message: "Enrollment created" });
} catch (error) {
next(error);
}
});