This is a RESTful API for a Todo List application built with:
- User authentication (register, login)
- CRUD operations for todo items
- Pagination todo items
- Input validation
- JWT-based authentication
- PostgreSQL database with Prisma ORM
Before you begin, ensure you have met the following requirements:
- Node.js (v16 or later)
- npm, yarn, or pnpm (recommended: pnpm)
- PostgreSQL database
-
Clone the repository:
git clone https://github.com/ivan-nr/todolist-api.git cd todolist-api
-
Install the dependencies:
pnpm install
-
Set up your environment variables by creating a
.env
file in the root directory:DATABASE_URL="postgresql://username:password@localhost:5432/db_name?schema=public" JWT_SECRET="your-key"
-
Run the Prisma migrations to set up your database schema:
pnpx prisma migrate dev
OR run the script in package.json
pnpm prisma:migrate
-
Build the TypeScript code:
pnpm build
-
Start the server:
pnpm start
For development, you can use:
pnpm dev
POST /auth/register
- Register a new userPOST /auth/login
- Login and receive a JWT token
GET /todos
- Get all todos (with pagination)GET /todos/:id
- Get a specific todoPOST /todos
- Create a new todoPUT /todos/:id
- Update a todoDELETE /todos/:id
- Delete a todo
POST /auth/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "securepassword123"
}
POST /auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "securepassword123"
}
POST /todos
Content-Type: application/json
Authorization: Bearer <your-jwt-token>
{
"title": "Buy groceries",
"description": "Milk, eggs, bread"
}
GET /todos?page=1&limit=10
Authorization: Bearer <your-jwt-token>
Contributions to this project are welcome. Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License.
If you have any questions, feel free to contact me at ivanngudi16@gmail.com