A simple TODO API built with Express.js and TypeScript with full CRUD functionality.
src/
├── controllers/ # Request handlers
├── models/ # Data models and interfaces
├── services/ # Business logic
├── routes/ # API routes
└── index.ts # Server entry point
- ✅ Create, Read, Update, Delete todos
- ✅ Mark todos as completed/incomplete
- ✅ CORS enabled for all domains
- ✅ TypeScript support
- ✅ Clean separation of concerns
npm installnpm run devnpm run buildnpm startPOST /api/todos- Create a new todoGET /api/todos- Get all todosGET /api/todos/:id- Get a specific todoPUT /api/todos/:id- Update a todoDELETE /api/todos/:id- Delete a todoPATCH /api/todos/:id/complete- Mark todo as completedPATCH /api/todos/:id/incomplete- Mark todo as incomplete
GET /health- Check if server is running
curl -X POST http://localhost:3000/api/todos \
-H "Content-Type: application/json" \
-d '{"title": "Learn TypeScript", "description": "Complete TypeScript tutorial"}'curl http://localhost:3000/api/todoscurl -X PUT http://localhost:3000/api/todos/{id} \
-H "Content-Type: application/json" \
-d '{"title": "Updated Title", "description": "Updated Description"}'curl -X PATCH http://localhost:3000/api/todos/{id}/completecurl -X DELETE http://localhost:3000/api/todos/{id}The API is configured to accept requests from any origin. This is set in src/index.ts:
app.use(cors());To restrict CORS to specific domains, modify the middleware:
app.use(cors({
origin: 'https://yourdomain.com'
}));ISC