Nav

To Simulate Calling a RAML API (Mocking)

Simulating calls to the API is a critical design task that helps you troubleshoot problems and demo the API to prospective users even before you have implemented it. You can simulate calls to the API in Design Center before publishing the API, or in Exchange after publication there. To simulate calls to the API, you need to include a few things in the definition of a RAML resource at design time:

  • An example of data the actual implementation would return

  • An HTTP status code the API returns if successful

The mocking service can provide a base URI for an API you haven’t implemented yet. The mocking service reacts to http requests by returning responses based on your RAML design.

This example builds on the Placeholder API example and simulates a call to the API in Design Center. The steps to simulating calls to the API in Exchange after publication are similar.

In this example, when you simulate a successful call to the API, the mocking service returns the status code 200 and example data as coded in the RAML. You see the response example from the JSON example when you preview the /users resource.

  1. After entering RAML code in the editor, click the hamburger menu if necessary to display resources.

    Files

  2. Turn on Mocking Service on the top right to simulate calls to the API.

    Files

    In your RAML definition, the baseUri changes to a mocking service URI.

  3. Expand resources to see methods. Click GET. Try It appears.

    Try It control
  4. Click Try It. Click Send to return the example data.

    The user information in the /users resource appears.

  5. Click the GET tab for the /userbyid resource. Click Try it.

  6. Check Show Optional Parameters, and accept the default query parameter ID = 3. Click Send.

    The user information appears for the user having an ID 3.

Turn off the mocking service before publishing to Exchange.

In this topic: