Skip to content

A RESTful Todo API built with Express.js and MongoDB. Features CRUD operations for managing tasks with proper error handling and data persistence. Uses Mongoose ODM for MongoDB interactions and includes middleware for error handling and CORS support.

Notifications You must be signed in to change notification settings

SuchitArtal/todo-list-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Todo List API

A RESTful Todo API built with Express.js and MongoDB. Features CRUD operations for managing tasks with proper error handling and data persistence. Uses Mongoose ODM for MongoDB interactions and includes middleware for error handling and CORS support.

Table of Contents

Features

  • ✨ Complete CRUD operations for todo items
  • πŸ“ MongoDB integration using Mongoose
  • πŸ”„ RESTful API endpoints
  • ⚑ Express middleware implementation
  • πŸ›‘οΈ Error handling and validation
  • 🌐 CORS enabled

Tech Stack

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • CORS
  • dotenv

Project Structure

todo-list-api/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ controllers/
β”‚ β”‚ └── todo.controller.js
β”‚ β”œβ”€β”€ models/
β”‚ β”‚ └── todo.model.js
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ └── todo.routes.js
β”‚ └── index.js
β”œβ”€β”€ .env
β”œβ”€β”€ .gitignore
└── package.json

API Endpoints

Todos

Method Endpoint Description
GET /api/todos Get all todos
GET /api/todos/:id Get a specific todo
POST /api/todos Create a new todo
PUT /api/todos/:id Update a todo
DELETE /api/todos/:id Delete a todo

Getting Started

  1. Clone the repository bash git clone https://github.com/SuchitArtal/todo-list-api.git cd todo-list-api

  2. Install dependencies bash npm install

  3. Set up environment variables Create a .env file in the root directory and add:

env PORT=3000 MONGODB_URI=mongodb://localhost:27017/todo-api

  1. Start MongoDB Make sure MongoDB is running on your system

  2. Run the application bash npm start

  3. Development npm run dev

  4. Production npm start

API Documentation

Todo Object Structure

{
  "_id": "string",
  "title": "string",
  "description": "string",
  "completed": "boolean",
  "createdAt": "date"
}

API Responses

Success Responses

  • 200: Operation successful
  • 201: Resource created
  • 204: Resource deleted

Error Responses

  • 400: Bad Request
  • 404: Resource not found
  • 500: Internal server error

Error Handling

The API returns error responses in the following format:

{
  "message": "Error message description"
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

ISC

About

A RESTful Todo API built with Express.js and MongoDB. Features CRUD operations for managing tasks with proper error handling and data persistence. Uses Mongoose ODM for MongoDB interactions and includes middleware for error handling and CORS support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published