This is a simple OpenWhisk serverless app written in Swift that will suggest a drink when asked. You can also view the top recommended drinks.
There are three actions available via web actions:
choose
: will recommend a drink for youcounts
: will show how often the top 10 drinks have been recommendedslackDrink
: expects to respond to "/drink please" and callschoose
There is one internal action:
incrementDrinkCount
: called fromchoose
to increment the number of times this drink has been recommended in Redis
-
Create
parameters.json
- start withparameters.json.dist
- Edit the information in
parameters.json
to connect to your Compose Redis instance
- Edit the information in
-
Read the makfile to see what to do:
make setup
to create the packagemake
to buld and upload all the actionsmake choose
to have a drink recommended to youmake counts
to view recommendation statsmake lastlog
will show the last activation's log
$ curl -s -H 'Content-Type: application/json' -H 'Accept: application/json' \
https://openwhisk.ng.bluemix.net/api/v1/experimental/web/{org}_{space}/DC/choose.http
{
"recommendation": "A nice hot cup of tea!"
}
$ curl -s -H 'Content-Type: application/json' -H 'Accept: application/json' \
https://openwhisk.ng.bluemix.net/api/v1/experimental/web/{org}_{space}/DC/counts.http
{
"results": [
{
"Anijsmelk": 28
},
{
"A nice hot cup of tea!": 23
},
{
"Hot chocolate": 21
},
{
"Espresso": 19
},
{
"Bandrek": 18
}
]
}
$ echo '-w "\n"' >> ~/.curlrc`
will ensure that curl always add a new line to the end of the response for neatness
web action calls:
choose: $ curl -i -H 'Accept: application/json' https://openwhisk.ng.bluemix.net/api/v1/experimental/web/{org}_{space}/DC/choose.http
counts: $ curl -i -H 'Accept: application/json' https://openwhisk.ng.bluemix.net/api/v1/experimental/web/{org}_{space}/DC/counts.http
API Gateway calls:
If you set up API Gateway access to the actions, then this is how you would call them:
choose: curl -i -H 'Accept: application/json' https://{some string}-gws.api-gw.mybluemix.net/DC/choose
counts: curl -i -H 'Accept: application/json' https://{some string}-gws.api-gw.mybluemix.net/DC/counts
A neat way to get the correct URL for the API Gateway calls is:
choose:
$ api_url=`wsk api-experimental list | grep DC/choose | awk 'END {print $NF}'`; curl -i $api_url
count:
$ api_url=`wsk api-experimental list | grep DC/count | awk 'END {print $NF}'`; curl -i $api_url
When you first start, you need to authorise your wsk
command with OpenWhisk:
1. https://console.ng.bluemix.net/openwhisk/learn/cli
2. Copy "New Authentication" command and paste into console
3. Unset namespace: `wsk property unset --namespace`