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.
After entering RAML code in the editor, click the hamburger menu if necessary to display resources.
Turn on Mocking Service on the top right to simulate calls to the API.
In your RAML definition, the baseUri changes to a mocking service URI.
Expand resources to see methods. Click GET. Try It appears.
Click Try It. Click Send to return the example data.
The user information in the
Click the GET tab for the
/userbyidresource. Click Try it.
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.