Simple proof of concept web-service / API in Go.
go: >= 1.15
postgresql >= 11.x
apt-get install postgresql postgresql-client
sudo -u postgres psql postgres
After dropping into the postgres shell change the password
#\password
Enter new password:
123456
\q
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=postgres
export DB_PASSWORD=123456
export DB_NAME=test
Run go test
in the storage
package to initialize the database schema
(see storage_test.go
).
make run
or equivalently
go run cmd/api/api.go
psql -U postgres -d test -a -f storage/00.sql
Create a product.
Example request
curl --header "Content-Type: application/json" \
--request POST \
--data '{"sku":"9a982384y932", "attrs":{"mass":"undefined"}}' \
http://localhost:8080/product/create
Lookup a product by SKU.
Example request
curl "http://localhost:8080/product/get?sku=9a982384y932" | jq
List products (paginated).
Example request
curl "http://localhost:8080/product/list?lo=0&hi=10" | jq
Delete a product
Example request
curl "http://localhost:8080/product/delete?sku=9a982384y932" | jq
### Health
The healthz endpoint returns the server's health status; when the server
is started if backing systems are unreachable, all other endpoints will
respond with `HTTP 503 ServiceUnavailable`
Example request
```sh
curl http://localhost:8080/healthz