To Simulate Calling a RAML API (Mocking)
Requires November 2017 Release
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. After a successful call to the API, the mocking service returns the status code 200 and example data you coded in the RAML.
After entering RAML code in the editor, the API Summary displays 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, and then click Send.
The user information in the
Click the GET tab for the
/userbyidresource. Click Try it.
Check Show Optional Parameters, and enter a 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.