https://github.com/nbaztec/potions-rest-api
https://github.com/nbaztec/potions-rest-api
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/nbaztec/potions-rest-api
- Owner: nbaztec
- Created: 2016-09-30T06:45:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-30T06:46:13.000Z (over 9 years ago)
- Last Synced: 2025-02-04T17:28:22.569Z (over 1 year ago)
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# About
Test potions is a simple REST test service that exposes the following end points:
## Authorization
The service is protected by a secret key that is set at the server level.
All API communication expects an `Authorization` header
containing the **base64 encoded** secret key as the header value.
The default secret key is: **mixOfRandomPotions**
## GET, POST /
Check API health.
**status** string
**version** string
## GET /list
Retrieve list of potions.
**items** list of potions having the format:
* **id** integer
* **name** string
## GET /item?id=XX
Retrieve detailed information about a single potion.
**item** list of potions having the format:
* **id** integer
* **name** string
* **toxicity** float
## POST /mix
Mix 2 or more potions and return the final toxicity.
Request JSON body:
**ids** list of potion IDs. Eg: `{ "ids": [2, 5, 6] }`
Response JSON body:
**toxicity** Resulting toxicity achieved by mixing the requested potions
# Run
```
$ go build
$ ./potions-rest-api
```
# Test
```
$ go test ./...
$ go test ./... -cover
```
# CURL Examples
```
$ curl -H 'Authorization:XXXXX' /
{"status":"Ok","version":"1.0"}
$ curl -H 'Authorization:XXXXX' /list
{"items":[{"id":1,"string":"Acidic Tonic"},{"id":2,"string":"Brew of Exalted Cats"},{"id":....
$ curl -H 'Authorization:XXXXX' /item?id=1
{"item":{"id":1,"string":"Acidic Tonic","toxicity":10.5}}
$ curl -X POST -H 'Authorization:XXXX' /mix --data '{"ids": [1,2,3]}'
{"toxicity":55.9}
```