A RESTful Todo API built with Express.js and TypeScript for managing your todo tasks efficiently.
- ✅ List all todos
- ✅ Get a specific todo by ID
- ✅ Create new todos
- ✅ Update todo titles
- ✅ Mark todos as completed
- ✅ Delete todos
- ✅ TypeScript for type safety
- ✅ Clean error handling
- ✅ JSON responses
- Node.js - Runtime environment
- Express.js - Web framework
- TypeScript - Type-safe JavaScript
- In-memory storage - Simple data persistence
- Clone the repository:
git clone https://github.com/dconco/express-todo-app.git
cd todo-app
- Install dependencies:
npm install
- Run the development server:
npm run dev
The server will start on http://localhost:3000
Method | Endpoint | Description | Body | Query |
---|---|---|---|---|
GET |
/ |
Get all todos | - | - |
GET |
/:id |
Get todo by ID | - | - |
POST |
/new |
Create new todo | { "title": "string" } |
- |
PATCH |
/update |
Update todo title | { "title": "string" } |
id=123 |
PATCH |
/completed |
Mark todo as completed | - | id=123 |
DELETE |
/delete |
Delete todo | - | id=123 |
GET /api/
Response:
{
"success": true,
"data": [
{
"id": 1,
"title": "Learn TypeScript",
"completed": false
}
]
}
POST /api/new
Content-Type: application/json
{
"title": "Build awesome API"
}
Response:
{
"success": true,
"data": {
"id": 123456789,
"title": "Build awesome API",
"completed": false
}
}
GET /api/1
Response:
{
"success": true,
"data": {
"id": 1,
"title": "Learn TypeScript",
"completed": false
}
}
PATCH /api/update?id=1
Content-Type: application/json
{
"title": "Master TypeScript"
}
Response:
{
"success": true,
"data": "Title Updated"
}
PATCH /api/completed?id=1
Response:
{
"success": true,
"data": "TODO Completed"
}
DELETE /api/delete?id=1
Response:
{
"success": true,
"data": "Deleted Successfully."
}
All error responses follow this format:
{
"message": "Error description"
}
400 Bad Request
- Missing required fields (title, id)404 Not Found
- Todo with specified ID doesn't exist
npm run dev # Start development server
npm run build # Build for production
npm start # Start production server
type Todo = {
id: number
title: string
completed: boolean
}
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Built with ❤️ by a senior developer 🔥
Happy coding! 🚀