← Back to Course

Project 01: Task Management API with Testing Suite

Phase 1: Solidifying Fundamentals
Why This Project?

This is your foundation project. Most web applications need to handle data - creating, reading, updating, and deleting records. This project teaches you how to build APIs the right way from the start.

Testing is included because writing tests as you code helps you catch bugs early and makes your code more reliable. In real jobs, companies expect code to have tests. Learning this now will make you a better developer and help you ship code with confidence.

You'll learn proper error handling so your API doesn't crash when users send bad data. You'll also learn how to validate inputs, which keeps your database clean and your application secure.

Overview

Build a RESTful API from scratch with comprehensive test coverage. This project emphasizes proper API design patterns, error handling, validation, and professional testing practices that you'll use throughout your career.

You'll create a task management system where users can create, read, update, and delete tasks. The focus is not on building something novel, but on building something correctly with industry-standard practices.

Learning Objectives

Master RESTful API design principles and conventions

Write comprehensive unit and integration tests with high coverage

Implement proper error handling and validation middleware

Structure a Node.js project following best practices

Use HTTP status codes correctly and consistently

Document your API with clear examples

Core Requirements (and Why)

RESTful endpoints for CRUD operations - This is the standard way APIs work. Learning REST patterns means you can work with any modern API.

Task model with multiple fields - Real applications have complex data. This teaches you how to structure database models properly.

Input validation - Never trust user input. Validation prevents bad data from entering your database and stops security issues.

Proper HTTP status codes (200, 201, 400, 404, 500) - Status codes tell clients what happened. Using them correctly makes your API easier to work with.

Error handling middleware - Catches all errors in one place. This keeps your code clean and makes debugging easier.

At least 80% test coverage - Tests prove your code works. They also help you catch bugs when you make changes later.

MongoDB/Mongoose - NoSQL databases are common in modern apps. Mongoose makes working with MongoDB much easier.

Environment configuration - Never hardcode passwords or API keys. Environment variables keep sensitive data safe.

Helpful Resources

REST API Basics: Search for "REST API tutorial" or "RESTful API design principles". Learn about HTTP methods (GET, POST, PUT, DELETE) and what each one does.

Express.js: Official Express documentation at expressjs.com. Look for routing and middleware sections.

Testing with Jest: Jest documentation at jestjs.io. Start with "Getting Started" and then look at "Testing Asynchronous Code".

Supertest: GitHub page for Supertest. It's simple - just look at the examples in the README.

Mongoose: Official docs at mongoosejs.com. Focus on schemas, models, and basic CRUD operations.

Validation: Look up express-validator or Joi validation library documentation. Both have clear examples.

API Endpoints to Implement

GET /api/tasks - Retrieve all tasks with optional filtering by status or priority

GET /api/tasks/:id - Retrieve a single task by ID

POST /api/tasks - Create a new task

PUT /api/tasks/:id - Update an existing task

DELETE /api/tasks/:id - Delete a task

GET /api/tasks/stats - Get statistics (total tasks, by status, by priority)

Technical Challenges

Write tests before implementing features (test-driven development approach)

Handle edge cases like invalid IDs, duplicate entries, and missing fields

Implement query parameters for filtering and sorting

Create reusable middleware for validation and error handling

Set up separate test and development databases

Mock database operations in unit tests

Testing Requirements

Unit tests for each controller function

Integration tests for each API endpoint

Test successful operations (happy paths)

Test error cases (validation failures, not found, server errors)

Test edge cases (empty database, invalid data types)

Use beforeEach/afterEach hooks to clean test database

Separate test configuration from development configuration

Bonus Features

Add pagination to the GET all tasks endpoint

Implement search functionality (search by title or description)

Add due date field with validation (must be future date)

Create a simple API documentation page or README with examples

Add request logging middleware

Implement rate limiting for API endpoints

Success Criteria

All CRUD operations work correctly and return appropriate status codes

All tests pass with at least 80% coverage

Invalid requests are handled gracefully with clear error messages

Code is organized into logical modules (routes, controllers, models, middleware)

API responds consistently and predictably

You can explain every design decision you made

Hint: Start by designing your API endpoints on paper or in a document before writing any code. Think about what data each endpoint needs, what it returns, and what could go wrong. Then write tests for those cases before implementing the actual logic.

Focus on making your error messages helpful. When validation fails, tell the developer exactly what went wrong and how to fix it.

Submit Your Project

Once you've completed this project, submit your GitHub repository link below: