A secure and efficient TODO list REST API built with Go, using Gin, GORM, SQLite, and JWT authentication. Built as a learning project following the Todo List API challenge.
Live URL:
β‘οΈ https://todoapi-nd4n.onrender.com
- β User registration and login with hashed passwords.
- π JWT-based authentication middleware.
- π CRUD operations for Todo items.
- π Pagination and filtering on todo list.
- π‘οΈ Per-user scoped data access.
- πΎ SQLite database (simple and lightweight).
- π§ͺ Unit-tested endpoints with GitHub Actions CI
- π§± Clean project structure with modular code.
TODOAPI/
βββ controllers/ # Request handlers
βββ db/ # DB initialization
βββ middleware/ # JWT auth middleware
βββ models/ # DB models
βββ utils/ # Shared helper functions
βββ .gitignore
βββ go.mod
βββ go.sum
βββ LICENSE
βββ main.go
βββ README.md
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /register |
Register a new user | β |
| POST | /login |
Authenticate user & get JWT | β |
| GET | /todos |
Get all todos (paginated) | β |
| POST | /todos |
Create a new todo | β |
| PUT | /todos/:id |
Update a todo | β |
| DELETE | /todos/:id |
Delete a todo | β |
git clone https://github.com/Agarwalsahil/TODOAPI.git
cd TODOAPICreate a .env file or set manually:
JWT_SECRET=your-secret-keygo mod tidygo run main.goServer will run at http://localhost:8080
POST /registerBody:
{
"name": "your name",
"email": "user@example.com",
"password": "securepassword"
}POST /loginBody:
{
"name": "your name",
"email": "user@example.com",
"password": "securepassword"
}Returns:
{
"token": "<jwt_token>"
}Include this header for all routes:
Authorization: Bearer <jwt_token>POST /todosBody:
{
"title": "Learn Go",
"description": "Finish GORM chapter"
}GET /todos?page=1&limit=5Defaults: page=1, limit=10
PUT /todos/:idBody:
{
"title": "Updated title",
"description": "Updated description"
}DELETE /todos/:idcurl -X POST http://localhost:8080/register -H "Content-Type: application/json" -d '{"name": "your name", "email": "user@example.com", "password": "pass"}'curl -X POST http://localhost:8080/login -H "Content-Type: application/json" -d '{"name": "your name", "email": "user@example.com", "password": "pass"}'curl -X POST http://localhost:8080/todos -H "Authorization: Bearer <token>" -H "Content-Type: application/json" -d '{"title": "New Task", "description": "Do it now"}'π‘ If you want to test the deployed version, replace
http://localhost:8080with:
π https://todoapi-nd4n.onrender.com
- Go β Programming language
- Gin β HTTP web framework
- GORM β ORM for database
- SQLite β Lightweight database
- JWT β Token-based authentication
- BCrypt β Password hashing
- Passwords are hashed using bcrypt before storing.
- JWT secret should be kept in a
.envfile (not committed). - Authorization middleware protects all todo routes.
This project is licensed under the MIT License.
Open to suggestions, bug reports, and pull requests!
Made with β€οΈ by Sahil Agarwal