http-postgres is a small Go HTTP API backed by PostgreSQL. It is designed as a Keploy sample application for recording and replaying HTTP traffic together with Postgres interactions.
The app starts with net/http, connects to Postgres using lib/pq, runs startup migrations automatically, and exposes two resources:
companieswith a serial integer IDprojectswith a UUID ID
POST /companiesGET /companiesGET /companies/{name}
POST /projectsGET /projectsGET /projects/{id}PUT /projects/{id}
- Go
1.24+ - Docker and Docker Compose
- Keploy CLI
Install Keploy:
curl --silent -O -L https://keploy.io/install.sh
source install.shgit clone https://github.com/keploy/samples-go.git
cd samples-go/http-postgres
go mod downloadStart the application and Postgres:
docker compose up --buildThe API will be available at http://localhost:8080.
Start recording:
keploy record -c "docker compose up" --container-name api --delay 10In another terminal, generate traffic using the bundled scripts:
./test.sh
./test_projects.shThis records API testcases and Postgres mocks into the keploy/ directory.
Run the recorded testcases:
keploy test -c "docker compose up" --container-name api --delay 20Keploy will replay the captured HTTP calls and mock the Postgres interactions during the test run.
If you want to run the app without Docker for the API process, start only Postgres through Compose:
docker compose up -d dbThen run the server with local environment variables:
DB_HOST=localhost \
DB_PORT=5433 \
DB_USER=postgres \
DB_PASSWORD=postgres \
DB_NAME=pg_replicate \
go run .- Database tables are created automatically on startup.
test.shfocuses on company creation, duplicates, validation, and listing flows.test_projects.shexercises UUID-based project create, get, update, and list flows.
