Demo Runbook
$ wsk api-experimental create /hello /echo get /whisk.system/utils/echo
Lets first implement a simple echoing API calling the OpenWhisk built-in echo action. This echo action just returns all request parameters as a result.
$ curl http://172.17.0.1:9001/api/3ae95da5-842f-45ae-afe1-3ddebae136e4/hello/echo
So we registered and got the access URL back. Lets use cURL to "call" this API. As expected when not specifying any parameters, we don't get anything back. Lets just add a greeting.
$ curl http://172.17.0.1:9001/api/3ae95da5-842f-45ae-afe1-3ddebae136e4/hello/echo?greeting=Hello+World
We can also list the routings configured with the API gateway using the "list" command:
$ wsk api-experimental list
For now we only have the echo API. Lets now.
We don't need this API any longer, so lets remove it:
$ wsk api-experimental delete /hello
Check it is removed by listing the APIs.
$ wsk api-experimental list
And just to be really sure, lets try to call it again, anyway:
$ curl -v http://172.17.0.1:9001/api/3ae95da5-842f-45ae-afe1-3ddebae136e4/hello/echo?greeting=Hello+World
As expected this fails with a 404/Not Found
status.
One nice feature of the current experimental integration is support for configuring APIs with Swagger JSON files. I have prepared such a file "bookClub.json" from which we can create the API using the "--config-file" option to the create command:
$ wsk api-experimental create --config-file bookClub.json
Beware this just configures the API gateway routing. The actions may not actually exist yet. So requesting the URLs may yield an error such as 404/Not Found:
$ curl -v http://172.17.0.1:9001/api/3ae95da5-842f-45ae-afe1-3ddebae136e4/club/book
So lets quickly define the actions:
$ wsk action create getBooks getBooks.js $ wsk action create putBooks putBooks.js
Calling again returns as expected:
$ curl http://172.17.0.1:9001/api/3ae95da5-842f-45ae-afe1-3ddebae136e4/club/book
Requesting the URLs through the API gateway will map request parameters to function parameters. Lets test this with a simple book upload:
$ curl -XPOST http://172.17.0.1:9001/api/3ae95da5-842f-45ae-afe1-3ddebae136e4/club/book?file=myFile\&title=some+meaningless+stuff
Or
$ curl http://172.17.0.1:9001/api/3ae95da5-842f-45ae-afe1-3ddebae136e4/club/book?file=book01
For completeness you can extract the API in Swagger format and store in a local file:
$ wsk api-experimental get "Book Club" > bookClub.$$.json
And finally clean up again:
$ wsk api-experimental delete "Book Club"
And check:
$ wsk api-experimental list