Golang Gin API
The API is built using GIN, a high-performance web framework for Golang. GIN provides a robust set of features for building web applications and microservices.
Endpoints
The API exposes several endpoints for interacting with the coupon service. Below are some example curl
commands to interact with these endpoints once the service is deployed:
- Create a coupon:
This endpoint allows you to create a new coupon. The request body should include the discount percentage, the coupon code, and the minimum basket value for the coupon to be applicable.
curl -X POST http://localhost:8080/api/create -d '{"discount": 10, "code": "Superdiscount", "minBasketValue": 50}' -H "Content-Type: application/json"
- Apply a coupon:
This endpoint allows you to apply a coupon to a basket. The request body should include the basket value and the coupon code.
curl -X POST http://localhost:8080/api/apply -d '{"basket": {"value": 100}, "code": "Superdiscount"}' -H "Content-Type: application/json"
- Retrieve coupons:
This endpoint allows you to retrieve the details of a specific coupon. The request body should include the coupon code.
curl -X GET http://localhost:8080/api/coupons -d '{"codes": ["Superdiscount"]}' -H "Content-Type: application/json"
- Retrieve many coupons:
This endpoint allows you to retrieve the details of multiple coupons at once. The request body should include an array of coupon codes.
curl -X GET http://localhost:8080/api/coupons -d '{"codes": ["Superdiscount1", "Superdiscount2", "Superdiscount3"]}' -H "Content-Type: application/json"
- Check HTTP response count and metrics:
This endpoint provides metrics about the service, such as the HTTP response count. It uses Prometheus, a powerful open-source monitoring and alerting toolkit.
curl -X GET http://localhost:8080/metrics
This version of the document provides more technical details about each endpoint, including what each endpoint does and what the request body should include.