Skip to content
This repository was archived by the owner on Nov 11, 2023. It is now read-only.

bwsd0/api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API

Simple proof of concept web-service / API in Go.

  1. API
    1. Requirements
    2. Installation
      1. Database setup
      2. Start the server
    3. Usage
      1. Error model
      2. Create
      3. Lookup
      4. List
      5. Health

Requirements

go: >= 1.15
postgresql >= 11.x

Installation

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

Database setup

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).

Start the server

make run

or equivalently

go run cmd/api/api.go

Usage

psql -U postgres -d test -a -f storage/00.sql 

Create

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

Lookup a product by SKU.

Example request

curl "http://localhost:8080/product/get?sku=9a982384y932" | jq

List

List products (paginated).

Example request

curl "http://localhost:8080/product/list?lo=0&hi=10" | jq

Delete

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

About

Simple proof of concept API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published