Republished from the OpenWhisk blog
We have been hard at work on a cool new addition to the OpenWhisk platform, the OpenWhisk Web Editor.
If you’re just tuning in, OpenWhisk is a serverless platform for hosting your applications. Using OpenWhisk, you can host your mobile, IoT, and web backends without worrying about deploying and maintaining servers. You can also use OpenWhisk to automate server-side processing of events. See the official announcement for more details about the core of OpenWhisk.
In this post, we introduce the OpenWhisk Editor:
Our new editor allows you to quickly get up to speed with the OpenWhisk programming model. Along with the editor we are also releasing the OpenWhisk Catalog Viewer. Check it out; it’s a great place to learn about the emerging OpenWhisk ecosystem of re-usable actions and triggers.
Watch the OpenWhisk Editor in Action
Quick Overview of the OpenWhisk Editor
Until now the Command Line Interface (CLI) has been the only tool for crafting your OpenWhisk application. The OpenWhisk Editor provides an alternative to the daunting flexibility of CLI by helping you accomplish three common tasks: writing new actions, composing your code with third-party offerings into larger applications, and automating the invocation of your code.
Task 1: Write and Debug New Code
Sometimes you need to bridge existing components together in a novel way. For example, you may need to align JSON schemas or implement custom logic for filtering or grouping. Perhaps you would like to use an analytical component that adds value to your application. In OpenWhisk, you create such bridging or analytic components by authoring a new Action:
To create a new action in the OpenWhisk Editor, you first click New Action. Next, write the code, keeping in mind that OpenWhisk actions take JSON as input, and return a JSON object as their output; and they can also call console.log to aid in debugging. After writing the new action, you can invoke it by clicking Run This Action. You will then see the output of your action presented in the Console section:
In OpenWhisk, since every action or feed you create automatically becomes a REST endpoint, you can call the REST endpoint directly via cURL. To see an example cURL invocation, click REST Endpoint:
Task 2: Compose Your Code with Third Party Code
With OpenWhisk you can compose sequences by assembling a set of actions as inputs and outputs of each other. The result is a chain of actions that execute in the order you arrange them. You can start composing your sequence either from the blank composition interface or by selecting an existing action from the public catalog. For example, you may want a composition that uses IBM’s Watson analytics or The Weather Company’s weather forecast service. If this were your starting point, you would click on the one in Public Actions that interests you, displaying it in the Catalog Details view. Click Start a New Sequence to open the Sequence Editor already populated with your chosen public action—in this case, the weather forecast action:
After clicking “Start a New Sequence”
After dragging your action
For more information, see Introducing the OpenWhisk Catalog Viewer. And in a future post, we will go through the process of binding and configuring third-party actions.
Continuing with the assembly of our sequence, drag any other action onto the canvas. You will see that you can form sequences of arbitrary length. Like UNIX pipes, OpenWhisk action sequences automatically feed each output as input to the next action. For example, you can personalize a weather forecast by having the next action in the sequence take the output of the general weather forecast action and filter it to present only tomorrow’s high temperature.
Finally, to invoke the sequence you composed, simply click Run This Sequence.
Task 3: Automate Your Compositions
We have learned how to manually invoke an action and sequence.
You can also schedule OpenWhisk to invoke your creations by using a public feed. For example, start a new sequence by selecting the alarm feed from the Public Feeds section of the catalog. Let’s say you want the sequence to kick off every minute:
Periodic Weather Forecast
The alarms feed will execute whatever actions you connect to it in the sequence, turning the feed into a trigger for your actions. Using cron notation, configure the feed to kick off the sequence at whatever internal you want.
Share this post: