Skip to content

thetechmaze/todo-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TODO API

A simple TODO API built with Express.js and TypeScript with full CRUD functionality.

Project Structure

src/
├── controllers/     # Request handlers
├── models/         # Data models and interfaces
├── services/       # Business logic
├── routes/         # API routes
└── index.ts        # Server entry point

Features

  • ✅ Create, Read, Update, Delete todos
  • ✅ Mark todos as completed/incomplete
  • ✅ CORS enabled for all domains
  • ✅ TypeScript support
  • ✅ Clean separation of concerns

Installation

npm install

Development

npm run dev

Build

npm run build

Production

npm start

API Endpoints

Todos

  • POST /api/todos - Create a new todo
  • GET /api/todos - Get all todos
  • GET /api/todos/:id - Get a specific todo
  • PUT /api/todos/:id - Update a todo
  • DELETE /api/todos/:id - Delete a todo
  • PATCH /api/todos/:id/complete - Mark todo as completed
  • PATCH /api/todos/:id/incomplete - Mark todo as incomplete

Health Check

  • GET /health - Check if server is running

Example Requests

Create a Todo

curl -X POST http://localhost:3000/api/todos \
  -H "Content-Type: application/json" \
  -d '{"title": "Learn TypeScript", "description": "Complete TypeScript tutorial"}'

Get All Todos

curl http://localhost:3000/api/todos

Update a Todo

curl -X PUT http://localhost:3000/api/todos/{id} \
  -H "Content-Type: application/json" \
  -d '{"title": "Updated Title", "description": "Updated Description"}'

Mark as Completed

curl -X PATCH http://localhost:3000/api/todos/{id}/complete

Delete a Todo

curl -X DELETE http://localhost:3000/api/todos/{id}

CORS Configuration

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'
}));

License

ISC

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors