Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsok/vending
Vending machine
https://github.com/jsok/vending
Last synced: about 1 month ago
JSON representation
Vending machine
- Host: GitHub
- URL: https://github.com/jsok/vending
- Owner: jsok
- License: mit
- Created: 2014-11-15T01:04:38.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-06T03:12:05.000Z (about 10 years ago)
- Last Synced: 2024-10-16T00:31:34.280Z (3 months ago)
- Language: Go
- Size: 241 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
vending
=======Vending machine in golang
Configuration
-------------You should create a JSON file of the form:
```json
{
"denominations": [1, 5, 20, 50],
"slots": {
"A1": {"item": {"name": "Coke Cola", "price": 180}, "inventory": 20},
"etc": {}
}
}
```HTTP API
--------### POST `/api/purchase`
Purchase an item.
Example request:
```
curl http://localhost:5000/api/purchase \
-d "coins[]=100" \
-d "coins[]=50" \
-d "coins[]=50" \
-d "choice=A1"
```Example response:
```json
{
"id": "e13b7f80-6d58-11e4-9803-0800200c9a66",
"item": "Coke Cola",
"change": {"20": 1}
}
```### GET `/api/items`
List all the items in the vending machine.
Example request:
```
curl http://localhost:5000/api/items
```Example response:
```json
{
"slots": {
"A1": {"item": "Coke Cola", "price": 180, "available": true},
"A2": {"item": "Water", "price": 120, "available": false}
}
}
```### POST `/api/items/`
Stock a new item. Creates a new slot if it doesn't exist, otherwise replaces the existing item stocked in that slot.
Example request:
```
curl http://localhost:5000/api/items/A1 \
-d "name='Coke Cola'" \
-d "price=180" \
-d "inventory=20"
```Example response:
```json
{
"status": "OK"
}
```### PUT `/api/items/`
Refills an item.
Example request:
```
curl -X PUT http://localhost:5000/api/items/A1 \
-d inventory=1
```Example response:
```json
{
"status": "OK"
}
```### DELETE `/api/items/`
Sets an item as *OUT OF ORDER*. Will fail if the choice does not exist.
Example request:
```
curl -X DELETE http://localhost:5000/api/items/A1
```Example response:
```json
{
"status": "OK"
}
```