Workflow: Create, Run, and Test an APIkit Project

In this workflow, you build an APIkit project that imports a RAML. You run the API in Anypoint Studio and use API Console to simulate calls to the API.

Studio 6.0 or later is recommended for this procedure. The API you create covers two main tasks:

  • Updating vending machine data: to update the central database on each sale

  • Tracking inventory: to find out if a machine is low on stock

Create a New APIkit Project

This procedure launches the new project and generates a Main flow with an HTTP Listener, an APIkit Router, and references to flows to handle errors. The project support REST resources and methods. These flows, aptly called skeleton flows, are the bare minimum needed to support the RAML specification. The RAML file imported by this procedure resides in src/main/api.

  1. Download the example file to your local drive:

  2. Under the File menu, select New > Mule Project.

  3. In the New Mule Project wizard, enter a Name, myproject for example, Mule Runtime 3.8.0.

  4. Check Add APIkit Components. In the RAML File field, browse to and select the downloaded api.raml file.

    Project Settings for a New Mule Project, including Project Name, Runtime, Maven Settings, Version Control System Support, APIkit Settings, and API Definition.
  5. Click Finish.

Run and Test the Project

  1. Right-click the project name in the Project Explorer, then select Run As > Mule Application.

    The APIkit Console appears below the canvas, displaying the resource-action pairs exposed by the API.

    Resource action pairs exposed by the Remote Vending API example.
  2. Click Introduction under Documentation to view the API description.

    The main Introduction title and sentence map to the contents of documentation in the root section of the RAML file.

  3. Click /machines to expand the section. Expand GET: /machines, then click the tab labeled Try It.

    The baseURI is optional in a RAML-backed API, but required by the API Console Try It functionality; otherwise, Try-it is disabled.

    Example of the Try-it feature being disabled because baseURI is not present.

    In the RAML, you can use an arbitrary value, for example http://www.example.com for the baseURI.

  4. Click the GET button to send a test call to GET a list of machines.

    Get button is highlighted to test the get call.
  5. The API returns a list of machines.

    The output is the payload set on the message by the get:/machines:apiConfig flow.

      "count": 3,
      "machines": [
          "id": "ZX4102",
          "location": "Starbuck's, 442 Geary Street, San Francisco, CA 94102"
          "id": "ZX5322",
          "location": "Starbuck's, 462 Powell Street, San Francisco, CA 94102"
          "id": "ZX6792",
          "location": "Cafe La Taza, 470 Post Street, San Francisco, CA 94102"

Add Logic to the Project

For example purposes, add over-simplified logic to the project to use later in API Manager. Unlike the APIkit-generated flows, the flow you create during this procedure returns a result, a payload message, when you call the API from a browser.

  1. Drag an HTTP component to the canvas.

    Studio creates a flow named apiFlow by default.

  2. In the apiflow, select the HTTP Connector to open its properties editor.

  3. Click Edit-16x16 to edit the Connector Configuration global configuration element.

  4. Change the value of the Base Path as follows:


  5. Click OK.

  6. In the properties editor, change the Path setting from / to /test-policy.

  7. Drag a Set Payload component to the process area of apiFlow.

  8. Set the Value of the payload to test policy.

  9. Save the changes.

You can then deploy the APIkit project from Studio to Exchange, and apply and test policies via API Manager.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub