A simple NestJS CRUD API for task management with in-memory storage.
- GET /tasks - Retrieve all tasks
- POST /tasks - Create a new task with validation
- PATCH /tasks/:id - Toggle task completion status
- DELETE /tasks/:id - Remove a task
interface Task {
id: string; // Auto-generated UUID
title: string; // Task title (required)
description: string; // Task description (required)
isDone: boolean; // Completion status (default: false)
createdAt: Date; // Creation timestamp
}- Install dependencies:
npm install- Start the development server:
npm run start:devThe API will be available at http://localhost:3000
Use the provided tasks.http file with VS Code REST Client extension or any API client like Postman/Insomnia.
Create a task:
curl -X POST http://localhost:3000/tasks \
-H "Content-Type: application/json" \
-d '{"title":"Learn NestJS","description":"Complete the tutorial"}'Get all tasks:
curl http://localhost:3000/tasksToggle task status:
curl -X PATCH http://localhost:3000/tasks/{taskId}Delete a task:
curl -X DELETE http://localhost:3000/tasks/{taskId}src/
├── tasks/
│ ├── dto/
│ │ └── create-task.dto.ts # Validation DTO
│ ├── task.entity.ts # Task model
│ ├── tasks.controller.ts # REST endpoints
│ ├── tasks.module.ts # Module configuration
│ └── tasks.service.ts # Business logic
├── app.module.ts # Root module
└── main.ts # Application bootstrap
- @nestjs/core - NestJS framework
- class-validator - Input validation
- class-transformer - Data transformation
- uuid - Unique ID generation
The API validates input using class-validator decorators:
titleanddescriptionare required- Both must be non-empty strings
- Invalid requests return HTTP 400 with error details