Lab 1: Implement the Omni Channel API in Studio


In this first lab, you will use Anypoint Studio to create a Mule application where there will be one flow for each method of each resource (i.e. GET). Additionally you will use APIKit (as part of your Mule application) to process each REST requests, transform them to messages to be handled and processed by each flow.

The implementation will consist of a few steps

  1. Create a new Mule Project in Anypoint Studio from the Omni Channel API RAML

  2. Run the Mule app from Anypoint Studio

Then we will test this new API using the API Console.

Step 1: Create a new Mule Project from the RAML

In this step we will create a new Mule application in Anypoint Studio from the Omni Channel API RAML Definition. This will be the implementation of our REST API.

  1. Start Anypoint Studio from the desktop icon.

    module2 lab1 step1 1 studio logo
  2. When you open the Studio for the first time, you are going to be asked for the workspace where the projects are going to be saved. Select the one that comes by default.

    module2 lab1 choose workspace
  3. You are presented with the Anypoint Studio 7 Welcome Screen.

    module2 lab1 step1 2 welcome screen
  4. Scroll to the bottom if you want to know more on Studio. After that, press Continue to Studio.

  5. In the Workspace Launcher, use the default workspace directory location.

  6. From Anypoint Studio’s menu, select File > New > Mule Project to create a New Mule project. A Window will pop-up to define the details of this new application.

    module2 lab1 file new
  7. Give the project the name omni-channel-api-v1

  8. Select the Mule Server 4.3.0 EE.

  9. Under Import a Publish API we are going to import the RAML Spec from Exchange. Click on module2_lab1_plus_button and select from Exchange

    module2 lab1 new mule api project
  10. Once you clicked there, you will see a new window. You need to login to the Anypoiint Platform. So click on the Add Account button.

    module2 lab1 add account
  11. A new Login window will appear. Insert your credentials.

    module2 lab1 platform login
  12. In the Search field put Omni Channel

  13. Select the <username> Omni Channel Experience API that you created in Module 1 and click Add.

    If you haven’t done Module 1, you can import the Omni Channel Experience API. Be sure you aren’t choosing the one whose Publisher is Mulesoft

    module2 lab1 step1 6 import RAML
  14. Press Finish

  15. Check everything is fine. Be sure that the Scaffold flows from these API Specifications is checked.

    module2 lab1 check scaffold
  16. Now click Finish. This will create a skeleton project that implements your API.

    module2 lab1 step1 7 studio overview

    Let’s explore what was automatically generated.

  17. At the top of the diagram you will see a flow called api-main and api-console followed by flows, one for each method defined in the RAML.

    The flows below are defined by your API Design in the RAML file. Typically, there will be flows that look like this get:\resource, post:\resource, put:\resource, etc. Note that the name of the flow is very important for the APIkit router to be able to route the request to the appropriate flow - you don’t want to change these.

    When APIkit detects example data in the response of a method in the RAML it inserts a Dataweave Transform Message into the flow which returns the static response specified by the example data reference.

    The static response returned by the auto-generated Dataweave Transform Message allows you to test the API as a stub immediately after generation. Obviously these flows can be enhanced to provide more advanced mock services as well as evolve them into full API implementation as we will see in the next lab.


    This is the main flow. It exposes an HTTP service and processes the requests using the APIKit Router.

    The HTTP request will be converted to a mule message, and redirected to the requested flow by the APIKit router.

    By selecting the http listener one can take a look at the HTTP configuration, you will see that its listening for requests on http://localhost:8081/api.

    Inside the api-main flow also an Error-Handling block is included. In this block multiple On Error Propagate definitions are autogenerated for common API error responses such as METHOD_NOT_ALLOWED, BAD_REQUEST etc.


    This flow puts an item into a users shopping cart based on the user id. This put operation returns no response and therefore the Dataweave Transform Message processor is replaced automatically by a Logger message processor.


    This flow gets an order based on an order id


    This flow gets a product based on a product id


    This flow returns orders based on search criteria


    This flow returns products based on a search criteria


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


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

Step 2: Test the Generated API Project

  1. To test the API, let’s run it within Studio first. Right click the application.

  2. Select Run As > Mule Application.

    module2 lab1 step2 1 studio run as
  3. The application will start running, and the console will show the Mule Runtime logs

    module2 lab1 step2 2 studio console deployed

    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. . Test the application using the console. Click button Open Console on the APIkit Console tab.

    module2 lab1 step2 3 apikit console base url
  4. A browser window opens at: http://localhost:8081/console/.

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

  6. Click the SEND button on the top right to submit the request.

    module2 lab1 step2 4 browser apikit console tryit
  7. Then tick the Show optional parameters and fill them in as below and click SEND.

    module2 lab1 step2 5 apikit console get request

    Scrolling down the third pannel, you will see the mocked data that is defined in the imported RAML.

    module2 lab1 step2 6 apikit console response

    It is a live application deployed to the Mule runtime server but it is leveraging the RAML information to provide a “mocking” experience.

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

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

    module2 lab1 step2 7 studio stop


In this lab, we

  • Downloaded the API definition directly into Anypoint Studio and added as a dependency

  • Used the RAML specification to generate the initial implementation skeleton for the API.

  • Auto-generated a skeleton project to implement the API.

This lab shows how APIkit quickly allows developers to import the designed REST API (RAML and supporting artifacts) to enable rapid API logic implementation in the generated MuleSoft flows. The APIkit also deploys the interactive console with the MuleSoft flows. The lab shows the extent to which a developer can deploy an on-premise and interactive API from the API specification in RAML.

It is important to note that the implementation of an API is a real MuleSoft application and allowed us to test the end-to-end API. Building integration applications and exposing APIs do not require additional knowledge making it easy for MuleSoft developers to work on both integrations and APIs.

Congratulations! You have completed Lab 1.

Please proceed to Lab 2