Contact Us 1-800-596-4880

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, called skeleton flows, are the bare minimum structure needed to support the RAML specification. The RAML file imported by this procedure is located at src/main/api.

  1. Download the example file to your local drive:

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

  3. In the New Mule Project wizard, enter a Project Name (myproject, for example). Mule Server 3.8.0 will be selected by default in the Runtime section.

  4. Check Add APIkit Components.

  5. In the APIkit Settings section, select the downloaded api.raml example file.

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

Run and Test the Project

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

    The APIkit Console appears and displays the resource-action pairs exposed by the API.

  2. Click Introduction to expand the API description.

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

  3. In the Resource section, click /machines to expand GET: /machines.

  4. Click Try It label.

    The baseURI is optional in a RAML-backed API but is required by the API-Console Try It functionality. Try It is disabled if there is no baseURI.

    The Try It feature is disabled because baseURI is not present.

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

  5. To send a test call to get a list of machines, click GET.

    GET button is highlighted to test the get call.
  6. 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 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. To edit the Connector Configuration global configuration element, click the edit button.

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

    remote-vending

  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.

Deploy the APIkit project from Studio to Exchange, and apply and test policies via API Manager.