Contact Free trial Login

Simulate API Calls with the Mocking Service

The API mocking service enables you simulate the behavior of an API specification. The mocking service provides a test link to an API. The mocking service returns the responses (both HTTP status codes and example payloads) that are defined in your API specification, and is valuable for testing or for simply exploring how your API behaves.

When you add an endpoint to your API specification, API Designer automatcially generates a link to the API that you can use in a browser. You can also enable a public link that can be shared with users outside of Anypoint Platform.

The mocking service is a feature of Anypoint Platform and runs continuously. You can run the mocking service from the text editor, the visual editor, and from Anypoint Exchange. You can simulate calls to the API in API Designer before publishing the API specification to Exchange or in Exchange after publishing the API specification.

If you specified a base URI (RAML) or base path (OAS), API Designer enables you to use either the base URI or the mocking service when simulating an API call. API Designer does not make any changes to your APIs.

Before You Begin

You must have a project containing an API specification in API Designer. Also, you must define at least one endpoint in your API specification and each endpoint must have at least one method.

Simulate a Call to an API using an Internal URL

To access the internal URL, you must specify the authorization headers as part of the request URL. To test an API without supplying authorization headers, generate a mocking service public URL for this project.

  1. From API Designer, open the project containing the API you want to test.

    You can use either the text editor or the visual editor.

  2. Select the root file of your project.

  3. Click the Documentation icon in the right-hand tool bar.

  4. From the drop-down menu, select Summary.

  5. Click on the name of an end point.

  6. If you have defined baseURL in your API specification:

    • Click the Select server dropdown and select one of the following:

      • baseUri: uses the baseUri as defined in your API specification

      • Mocking Service: uses the API mocking service

  7. Click one of the methods of your API, then click Try it.

  8. (Optional) Provide and query paramaters you want to test.

    You can enter query parameters as name/value pairs.

  9. Click Send.

    API Designer displays the HTTP return code as specified in your API. Alternately, you can test the API by copying the Request URL and paste it into a web browser or Postman.

    When using the mocking service internal URL, you must provide authorization headers as part of the URL. To avoid this, use the mocking service public url.

Setting the Mocking Service as the Default Server

You can set the Mocking Service as the default server used in the Documentation panel. This is the default value that appears in the Select server drop-down.

  1. Click Mocking Service Configuration.

  2. Click the Select by Default slider.

Simulate a Call to an API using an Public URL

Use a public URL to test calls to your API without having to provide an authorization header. This is useful when you want to share the API with someone outside of Anypoint Platform.

  1. From API Designer, open the project containing the API you want to test.

    You can use either the text editor or the visual editor.

  2. Select the root file of your project.

  3. Click the Mocking Service Configuration icon in the right-hand tool bar.

  4. Click the Make Public slider.

    API Designer generates a public URL for your API. When you disable the public URL it becomes invalid. Re-enabling this option generates a different URL.

  5. (Optional) Set an expiration date for the public URL

    1. Click Set expiration date for public link.

    2. Using the date selector, select the day you want the public link to expire.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub