API Developer
In this step, you will confirm that the API for your Inventory Microservice Application is working correctly. You will run the microservice application locally, invoke the API and view the responses from the data source.

Update the API Assembly to use DataPower as an enforcement gateway

Your API Connect environment in Bluemix uses IBM DataPower to enforce API policies. You can test the API with a local version of the DataPower gateway running in Docker prior to publishing the API to the cloud.

  1. Click on the menu icon in the top left hand corner of the screen and select the inventory project to return to the API definitions section.

  2. Open the inventory 1.0.0 API definition.

  3. Click on the Assemble tab to switch views.

  4. Select DataPower Gateway Policies from the palette on the left.

  5. Save the API definition.

Test the Application and API locally

  1. On the bottom left-hand corner of the screen, locate and click on the Run button to start the inventory LoopBack application.

  2. Wait a moment while the servers are started. Proceed to the next step when you see the following:

  3. Click the Explore button to review your APIs.

  4. On the left side of the page, notice the list of paths for the inventory API. These are the paths and operations that were automatically created for you by the LoopBack framework simply by generating the item data model. The operations allow users the ability to create, update, delete and query the data model from the connected data source.

  5. Click the Item.find operation.

  6. By clicking the Item.find operation, your screen will auto-focus to the correct location in the window. In the center pane you will see a summary of the operation, as well as optional parameters and responses.

    On the right side you will see sample code for executing the API in various programming languages and tools such as cURL and an example response.

  7. Click on the Try it link to view the API test configuration screen.

  8. Click the Call operation button to invoke the API, scroll down to see the response.

  9. Scroll down to see the Request and Response headers.

    Request
    GET https://localhost:4002/api/Items Headers:
    Content-Type: application/json
    Accept: application/json
    X-IBM-Client-Id: default
    X-IBM-Client-Secret: SECRET
    
    Response
    Code: 200 OK Headers:
    x-ratelimit-remaining: 99
    content-type: application/json; charset=utf-8
    x-ratelimit-limit: 100
    
  10. Scroll further and the payload returned from the GET request is displayed.

    [
      {
        "id": 1,
        "name": "Dayton Meat Chopper",
        "description": "Punched-card tabulating machines and ...",
        "img": "images/items/meat-chopper.jpg",
        "price": "4599.99"
      },
      ...
    ]
    
  11. Test the Item.count operation by following the same process above. You should receive a count of inventory items.

    {
      "count": 12
    }
    
  12. Click on the Stop button to shut down the running application.

  13. Click on the X in the top-right portion of the screen to leave the API Explorer view.

Continue

Proceed to Proceed to Lab 2 - Run and Test your API in the Cloud.