A Go REST API to make a working API that fetch public API https://pokeapi.co/ to give RESTFUL response to React Vite frontend
- Go 1.21+, tested on
go1.25.5 X:nodwarf5 linux/amd64 - PostgreSQL 15, tested on
docker compose postgres 15-alpine - Docker, tested on
29.0.4, thus usinggo1.25.4by 18th December 2025 - PokeAPI, accessible on 18th December 2025
The API was tested on Fedora 43 but following requirement should be compatible with Windows and MacOS in their own ways.
git clone https://github.com/deanAirre/pokeGOAPI
cd pokeGOAPI
go mod download
sudo dnf install docker docker-compose
or
sudo apt install docker.io docker-compose
# Start docker service
sudo systemctl start docker
sudo systemctl enable docker
# Add user to docker group
sudo usermod -a6 docker $USER
newgrp docker
For Windows / Mac:
- Install Docker Desktop from https://www.docker.com/products/docker-desktop/
- Start PostgreSQL Database
docker compose up -d - Verify databse is running
docker ps - Run the API Server
go run main.go
Expected response:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
975066d55033 postgres:15-alpine "docker-entrypoint.s…" 4 seconds ago Up 3 seconds (health: starting) 0.0.0.0:5432->5432/tcp, [::]:5432->5432/tcp pokemongo-postgres
2025/12/18 14:57:15 Config loaded
2025/12/18 14:57:15 Database connected
2025/12/18 14:57:15 Migrations completed
2025/12/18 14:57:15 Server starting on http://localhost:8080 ```
Test the API
curl http://localhost:8080/health
Expected Response
{"status":"healthy", "service":"pokemon-api"}
Fetch data first from pokeAPI
curl -X POST http://localhost:8080/api/pokemon/sync
| Variable | Default Value | Description |
|---|---|---|
DB_HOST |
localhost | Database host |
DB_POST |
5432 | Database port |
DB_PASSWORD |
postgres Database | password |
DB_NAME |
pokemon_db | Database name |
SERVER_PORT |
8080 | API server port |
*The default password are meant only for first installation, for later production it is recommended to change the password for better security.
| Method | Endpoint | Description |
|---|---|---|
| GET /health | Health | check endpoint |
| GET /api/pokemon | pokemon | list all gen V pokemon |
| GET /api/pokemon/:id | pokemon/:id | get pokemon detail by id |
| GET /api/pokemon/sync | sync | sync data from pokeAPI |
docker logs pokemongo-postgres
docker logs -f pokemongo-postgres
docker compose restart postgres
docker compose down
docker compose down -v
docker compose up -d //turn it back on, clean slate
docker exec -it pokemongo-postgres psql -U postgres -d pokemon_db
sudo systemctl start docker
sudo systemctl stop docker
sudo systemctl restart docker
sudo systemctl status docker
sudo systemctl enable docker
sudo systemctl disable docker
Docker uses plenty of resources and personally recommended to be turned off in times it is not required to run. If sudden spike in RAM or CPU uses every startup, better check your docker compose
go run main.go
go build -o bin/pokemongo main/main.go ./bin/pokemongo
go test ./..
_"docker command not found"
Install docker following the installation steps above
_"permission denied while trying to connect to Docker"
Add your user to the docker group (linux solution)
sudo usermod -aG docker $USER
newgrp docker
"port 5432 is already in use"
Another PostgreSQL instance probably occupying the port, check your port with lsof or ss or netstat
sudo ss -tulpn | grep :5432
If it's like docker or postgresql then it is another instance of either still running from past operations.
Turn it off with
sudo systemctl stop postgresql
or
sudo systemctl stop docker
or might as well clean the docker-compose and start it again if needed
docker compose down
If necessary, or the port is necessarily occupied, change the port in docker-compose.yml
"container is restarting continously"
Check logs first with
docker logs pokemongo-postgres
docker logs -f pokemongo-postgres
Common causes:
- Permission issues with mounted files (initiating new .db or something)
- Port conflicts
- Corrupted Docker volume
Solution:
docker compose down -v
docker compose up -d
"Failed to load config:DB_PASSWORD required"
Probable postgresql config issues, may want to check
psql -U postgres
or if it's already in Docker
docker exec -it pokemongo-postgres psql -U postgres
then change the password
ALTER USER postgres PASSWORD 'new_password';
verify that it worked with ALTER ROLE or try logging in again
- "Database connection refuse"
Ensure Docker and PostgreSQL container are running
sudo systemctl status dockerdocker psdocker logs pokemongo-postgres
If it's on windows, nevermind the sudo part. If it's not running, try restarting it. If it's running but somehow still have that problem, well.. I'd recommend ask someone to debug it. In my experience it's postgresql not correctly installed, docker not correctly installed, version outdated, dependency not found, etc. Goodluck
For questions or support, please open issue on GitHub