1. Overview
  2. Step 1: Import the project from Anypoint Exchange
  3. Step 2: Examine the different flows within the project
  4. Step 3: Update Shopping Cart confirmation Flow (Optional)
  5. Step 4: Test the application
  6. Summary

Lab 2: Download the complete Omni Channel project

Overview

Now that we’ve seen how APIKit helps developers import the designed REST API to enable MuleSoft flow development, we’ll download a fully implemented Omni Channel API project.

Step 1: Import the project from Anypoint Exchange

  1. From Studio open exchange

  2. Filter by Examples

  3. Select the sub organization

  4. Click on the omni-channel-api

  5. In the portal press Open

    Once you open it, the project is going to be imported into Studio. (Perform any updates required)

Step 2: Examine the different flows within the project

The previous lab already introduced the APIKit, Error handling and Dataweave Transform Message processors. In the flows we’ll discuss in this section we introduce REST Connectors, Flow Control components and Scopes. So let’s first look at these in more detail.


REST Connector

A REST Connector is a component that can be used in Mule applications that’s been custom created via a specific framework. This framework allows you to create components entirely by using other existing Mule components. When an API Specification is published to exchange a REST Connector is automatically generated for it in Exchange by REST Connect Tool.


Flow Control

Flow Control Routers such as the Choice Router allows for controling the message flow within a Mule flow.


Scopes

Sometimes referred to as “wrappers”, the message processors known as Scopes appear as processing blocks when you first place them on the Message Flow canvas.

Now, lets look at all the flows within the project.


get:\orders\orders\{order_id}

This flow calls the Process API Order to get an order from the database based on the order id


get:\orders\search

This flow calls the Process API Order to get orders from the database based on a search


get:\products\product\{product_id}

This flow calls the System API Product to get a product based on the product id


get:\products\search

This flow returns products from the database by calling the System API Product


get:\users\user\{user_id}\shopping_cart

This flow returns all the items in a users shopping cart based on the user id


put:\users\user\{user_id}\shopping_cart

This flow puts an item into a users shopping cart based on the user id


post:\users\user\{user_id}\shopping_cart\confirmation

This flow confirms the items to purchase in a users shopping cart.

Step 3: Update Shopping Cart confirmation Flow (Optional)

In order to be able to confirm your order once it is placed, you might need to do some minor updates to the confirmation flow. You will be able to test this in the next lab once you have the application deployed.

  1. In the Mule Palette on the right of your screen, search for “Set variable”.

  2. Add the Set variable at the beginning of the confirmation flow

  3. Click on the Set variable and configure it with the following:

    a. Name: user_id

    b. Value: attributes.uriParams.user_id (remember to click the function button)

  4. Finally set a defaul value of 1 in the Create User Response transform. You do this by selecting the connector and updating the DataWeave expression for the quantity field. It should look like this:

     quantity: product.quantityOnHand as Number default 1,
    

Once you have done this step you will be able to complete the order placed in the next lab.

Save all your changes and proceed to the next step.

Step 4: Test the application

To test the API, let’s run it within Studio first.

  1. Right click the application.
  2. Select Run As > Mule Application.

  3. The application will start running, and the console will show the Mule Runtime logs

    Anypoint Studio deployed this application to an embedded Mule Runtime. There is no need to deploy to a separate Mule server environment. The developer will be able to develop and test the application locally until it’s ready to be deployed to a shared development or QA environment.

  4. Test the application using the console. Click the Open Console on the APIkit Console tab.

  5. A browser window opens at: http://localhost:8081/console/.

  6. Click open the /products/search resource on the left and click GET.

  7. Then tick the Show optional parameters and fill them in as below and click SEND.

  8. Unlike Lab 1, this project is a complete solution and is making calls to System and Process REST APIs. The response you see in the Console is coming from other sources.

    Let’s go ahead and stop the application to get ready for the next lab.

  9. Go to the console tab and press the red squared button to stop the Mule runtime server.

Summary

In this lab, we went trough all these steps:

This lab shows how quick and easy it is to enable your teams to get up and running quickly with pre-built project templates.

Congratulations! You have completed Lab 2.

You can now proceed to Lab 3