APIs of commonly used HTTP verbs GET, POST, PUT, and DELETE are implemented in a REST-ful manner using micro-services in Go.
-
Retrieve single product
-
Retrieve all products
-
Add a new product
-
Modify an existing product
-
Delete an existing product
{
ID: unique integer identifier for coffee product
Name: name of coffee (latte, espresso, etc.)
Description: brief information about coffee
Price: floating point values in USD
SKU: stock-keeping unit is a string separated by "-" after every third character
Manufactured On: string in UTC format
Expires On: string in UTC format
}
NOTE: Execute commands from project root
-
Run test cases (in verbose mode):
go test -v
-
Run Go server:
go run server.go
-
Open a new terminal tab and:
-
Get specific product:
curl localhost:8080/coffee/get/2 | jq
-
Get all products:
curl localhost:8080/coffee/get/all | jq
-
Create a new product:
curl localhost:8080/coffee/add -d '{"name": "Tea", "description": "A nice cup of tea!", "price": 2.0, "sku": "TEA-WAT-MIL-SUG"}' | jq
-
Replace an existing product:
curl localhost:8080/coffee/modify/3 -XPUT -d '{"name": "Mocha", "description": "Chocolate-flavoured variant of latte", "price": 3.00, "sku": "COF-MOC-VAR-LAT"}' | jq
-
Delete an existing product
curl localhost:8080/coffee/remove/2 -XDELETE
-