A professional, containerized RESTful API for managing a to-do list, built with standard library Go and a PostgreSQL database. This project is designed to showcase best practices in backend development, including a clean project structure, a multi-service Docker setup with Docker Compose, and a production-ready multi-stage Dockerfile.
- Full CRUD Functionality: Create, Read, Update, and Delete to-do items.
- Robust Database: Uses a networked PostgreSQL database for persistent, scalable storage.
- RESTful API Design: Follows standard REST principles for predictable and clean endpoints.
- Fully Containerized: A multi-stage
Dockerfilecreates a tiny, secure, static binary. - Local Development with Docker Compose: Includes a
docker-compose.ymlfor a one-command local development setup. - Production-Ready: Connects to a cloud database via environment variables for easy deployment.
Before you begin, ensure you have the following installed:
- Go (Version 1.24.6 or later)
- Docker & Docker Compose
This is the easiest way to run the entire application stack (API + Database) on your local machine.
-
Start the services:
docker-compose up --build
This command will build your Go API image, pull the PostgreSQL image, and start both containers.
-
Access the API: The API will be available at
http://localhost:8888. -
To stop the services: Press
Ctrl + Cin the terminal.
The Dockerfile is optimized for production deployment. A cloud provider like Render will use it to build and run your API, which will connect to a managed cloud database via the DATABASE_URL environment variable.
The base URL for all endpoints is http://localhost:8888.
- Method:
GET - Endpoint:
/todos curlExample:curl http://localhost:8888/todos
- Method:
POST - Endpoint:
/todos curlExample:curl -X POST -H "Content-Type: application/json" -d '{"task":"Deploy to the cloud", "completed":false}' http://localhost:8888/todos
- Method:
PUT - Endpoint:
/todos/{id} curlExample:curl -X PUT -H "Content-Type: application/json" -d '{"task":"Deploy to the cloud", "completed":true}' http://localhost:8888/todos/1
- Method:
DELETE - Endpoint:
/todos/{id} curlExample:curl -X DELETE http://localhost:8888/todos/1