1.2 Creating a Service

Creating a service with Warewolf is easy, and fast! Watch this video to learn how to create services and microservices. Simply drag your tools onto the design surface, configure variables, connect the nodes and you’re ready to run your web service.

If you hover over the top button labeled New, the New Service hint appears. Click this button to create a new microservice.

A new design surface will appear, containing only the Start node. If you look at the tab for the design surface on the Tab Bar, in the center of the screen, you will see that Warewolf has automatically called this tab “Unsaved 1.”

Just below the Tab Bar, in orange, you can see an underlined URL. When you create or rename a microservice, Warewolf automatically creates a URL for the microservice.

You can navigate between the different tabs by clicking on them, enabling you to work with multiple workflows at once.

When you click on the URL your default web browser automatically navigates to the URL. If you look at the URL in your browser address bar, you can see that it is the same as the URL in Warewolf.

Currently, the web browser window is empty; this is because the microservice doesn’t do anything yet.
At this point, Warewolf has created the service for you. You can execute this service regardless of whether the Studio is running or not.

So let’s make it do something. First, let’s go back into Warewolf.
In this exercise, we are going to build a “dice roll” microservice. It will return a random number between one and six.
To get started, save the microservice and name it DiceRoll. The second button on the left in the Menu bar is the Save button. Click it, and the Save Dialog box appears.

Warewolf will save your microservice as DiceRoll. In the top left window is the resource Explorer. The Explorer shows you all of the saved resources on your Warewolf Server.

You can see the microservice we have just saved as DiceRoll.

There are two ways to open a resource using the Explorer. The first is to double click on the resource in the Explorer. The other way is to right click on the Resource you want to open, and use the context menu to open the Resource.

Look back to the URL at the top of the designer, and you’ll see that it changed from Unsaved 1.json to DiceRoll.json.

In the bottom left pane is the Toolbox. The Toolbox contains over 60 pre-built logic tools and connectors that speed up software development. They take care of the ‘heavy lifting’ so you can focus on what the software needs to do, not on the details of how it’s done.

The tools in the Toolbox are grouped into the logical groups.
For the sake of this example, we are going to use a Utility tool called Random, which can be found under the Utility tab.

To get the Random tool into the workflow, drag it from the Toolbox onto the Start node on the design surface.
You’ll notice how when you get near the Start node, the connector arrow will appear at the bottom of it. When it does, you can drop the tool, and Warewolf will create the connector automatically.
When you hover over a tool, you’ll see at least four connector nodes. You can create a connector between two tools manually by connecting the nodes on two different tools.

The Random tool can generate four types of random strings and numbers; it defaults to generating random numbers. To generate a random number, we need to specify a range.
Since our goal is to roll a dice, we want a random number in the range between 1 and 6, so enter 1 in the From textbox, and 6 in the To textbox.

At the bottom of the Random tool is the Result field, which contains your first look at Warewolf variables.
A variable in Warewolf is a named value that can assume any value. Warewolf variables can be defined by adding a double square bracket at the beginning of a word, and a double square bracket at the end of a word. When you do this, Warewolf automatically recognizes it as a variable.

So add the Result variable to the result textbox by typing [[Result]].

When the Random tool runs in this configuration, it will select a random number between 1 and 6, and insert the chosen number into the [[Result]] variable.
This is how most of the Warewolf tools function. The tools start with Input variables, and produce Output variables.

The top right pane in Warewolf contains the Variables list.
If you look at the Variables List, you will see that it now contains a variable called Result. Warewolf automatically created the Result variable when we added it to the Result field in the Random tool.
Automatic variable creation is a huge time-saving feature that is built into Warewolf. Later on, we will look at how to take full advantage of this feature.
Warewolf can use variables in two ways: as Input variables or as Output variables. By default, all variables can be used by the workflow while it is running, so all variables are internal variables.

Input variables are variables that need to be provided to the service when it starts, and are used to configure the state of the workflow.
Output variables are values produced as the end result of running the service.

In this example we want our microservice to output the result of the dice roll, so we need to flag the Result variable as an Output variable, using the checkbox.

Now we are ready to run our microservice for the first time.
On the Main Toolbar, click the Debug Button.

The Debug dialog box will appear.

The Debug dialog box has two buttons at the bottom of the window that can run the workflow. To start with, let’s view the output in browser mode. You can either click the View In Browser button, or press F7.

In your browser, you will get XML output.

By default, Warewolf outputs an XML dataset called DataList. Inside Datalist, you can see our output variable: Result. In this case, is returning a dice roll value of 3.
If you refresh your browser, you can see that the value of changes randomly, and returns a number between 1 and 6.
If you look at the URL in the browser address bar, you can see that the microservice being called is named DiceRoll.xml.
If you change the .xml to .json the Warewolf microservice will return JSON  data instead of XML, without any extra work on your part.


Updated on June 22, 2018

Was this article helpful?

Related Articles

Enjoying Warewolf?

Write a review on G2 Crowd