A simple Todo application demonstrating how to build a CRUD API with Next.js API Routes.
- Complete CRUD functionality:
- Create new todo items
- Read all todos or a specific todo
- Update todo status (mark as completed/uncompleted)
- Delete todos
- Modern React patterns with hooks
- Server-side API routes with Next.js
- In-memory data storage (can be easily replaced with a database)
- Responsive UI with Tailwind CSS
- Node.js 18+
- npm or yarn
-
Clone the repository:
git clone https://github.com/yourusername/api-demo.git cd api-demo -
Install dependencies:
npm install # or yarn install -
Run the development server:
npm run dev # or yarn dev -
Open http://localhost:3000 with your browser to see the result.
- Get all todos
- Create a new todo
- Request body:
{ "title": "Your todo title" }
- Get a specific todo by ID
- Update a specific todo
- Request body:
{ "title": "Updated title", "completed": true }
- Delete a specific todo
/src
/app
/api
/todos
/[id]
route.ts # Individual todo endpoints (GET, PUT, DELETE)
route.ts # Collection endpoints (GET, POST)
/components
TodoList.tsx # Main component for todo management
page.tsx # Main application page
layout.tsx # Root layout
- Next.js - React framework
- React - UI library
- Tailwind CSS - Utility-first CSS framework
This demo uses an in-memory array to store todos. In a real application, you would replace this with a database like MongoDB, PostgreSQL, etc.