Creating mocks manually

Updated 3 months ago by Rahul Lahiri

You can create sample API requests and responses directly in the API Studio, and use them as API mocks to develop against. This is often necessary to enable concurrent development with dependencies.

Refer to the help docs for overview of how Mesh Dynamics translates between service names / API paths and URLs.

There must be a service name and an API path specified for every request in Mesh Dynamics. When creating the mocks in the API editor, you must provide a service name and path for every mock request that you create. We recommend that whenever possible, use service names that will be meaningful to the consumers of the API mocks.

Create an API mock

  1. From the API editor, create a collection to store the sample requests.
  2. In the API editor, open a tab and expand the Trace section.
  3. In the trace, enter a service name. For this example, let’s name the service movieinfo. To edit the service name, click on the edit icon.
  4. Enter a service name in the box and hit Enter.
  5. Select the request type (GET / POST etc.) and enter the API path. The request path should match the expected request that you will receive.
    Note the differences in the host/service/path specification when using a live API to generate the mock (both request sent to localhost and request sent to a dev cluster) vs. when creating mocks manually. When sending the requests to a live API, the service name/API path are generated from the request URL. When creating the mocks manually, we are entering the service name (movieinfo) and the path (minfo/listmovies) separately.
  6. Add query parameters, body parameters, and headers as required.
  7. Create the expected response for the request in the left response pane using the built-in JSON editor.
  8. Save the request to the collection.

The API path for the saved request is:

Service: movieinfo 
API path: /minfo/listmovies

Create as many requests as you need and add them to the collection. Once created, the collection is immediately available for all your collaborators to use either as mocks or as sample requests.

What is the URL?

The API path does not look like a full HTTP request, does it? Nor does it look like the requests captured from APIs? It does not. In the next section, we go over these questions, and explain how to convert the mocks to use a common URL format.

How did we do?