This example builds on the "Hello World" Action example by adding an API definition on top of that action so that I can be queried via an HTTP call.
It shows how to:
- update the Action named ‘hello_world’ to expose it to the gateway.
- specify the API's endpoint that will trigger the action.
packages:
hello_world_package:
version: 1.0
license: Apache-2.0
actions:
hello_world:
function: src/hello.js
annotations:
web-export: true
apis:
hello-world:
hello:
world:
hello_world:
method: GETThere are two key changes to this file:
- the
hello_worldaction now has theweb-exportannotation set totrue. - a new
apisblock has been created.
The apis block contains a number of groups of API endpoint. Each endpoint is then defined by the hierarchy. In this case, we are creating the hello/world endpoint. The leaf in the structure specifies the action to trigger when the given HTTP verb is sent to that endpoint, in this case, when the HTTP verb GET is used on the hello/world endpoint, trigger the hello_world action.
You can actually deploy the "hello world API gateway" manifest from the openwhisk-wskdeploy project directory if you have downloaded it from GitHub:
$ wskdeploy -m docs/examples/manifest_hello_world_apigateway.yamlCheck the full URL of your API first:
$ wsk api listThis will return some information on the API, including the full URL, which
should end with hello/world. It can then be invoked:
$ curl <url>The invocation should return a JSON response that includes this result:
{
"greeting": "Hello, undefined from undefined"
}The output parameter 'greeting' contains "undefined" values for the 'name' and 'place' input parameters as they were not provided in the manifest or the HTTP call. You can provide them as query parameters:
$ curl <url>?name=World&place=EarthThis "hello world" example represents the minimum valid Manifest file which includes only the required parts of the Package, Action and API descriptors.
The source code for the manifest and JavaScript files can be found here:
For convenience, the Packages and Actions grammar can be found here: