9. Dependencies and Concurrent Development

Updated 2 months ago by Rahul Lahiri

In the previous step, you used API Studio to send requests to the service in your IDE with the assumption that all other upstream services are available. Quite often that is not the case. One of the benefits of microservices is that when a new capability requires changes to multiple services, the development can be done in parallel by independent teams, as long as the contracts are clearly defined. Here we will go over how API Studio helps when services are being developed in parallel by multiple teams. Concurrent development is covered in detail in the How-To section.

Parallel Development of Dependent Services

Now we are going to make a change to the movieinfo service in your IDE. The modified functionality will also require a change to the details service -- movieinfo will look for a new country element in the response coming back from the details service.

When changes to a service require changes to upstream services, there are two common options – either wait for the upstream service changes to become available in the dev cluster, or create mocks for the upstream service based on the updated contract. Both options are supported by API Studio.

  • Creating mocks from API Studio: This is useful when the upstream service changes are not yet available. Traditionally, creating mocks manually is a resource-intensive process, and mocks created are hard to maintain. API Studio makes the process easier by allowing developers to start from existing examples, captured either from CI run or from egress requests from the developers' laptops.
  • Send egress request to the dev cluster: The option can be used if the updated service is already available.

We are going to create new mocks by leveraging existing data for similar requests. The process will involve the following steps:

  • Update the movieinfo service running in the IDE.
  • The updated movieinfo service will look for a country item in the response from the details service. We will take an existing trace of the movieinfo/listmovies API request, and update the details response manually to create a mock that represents the updated contract.
  • Then we will validate the movieinfo service change using the updated mock.

Update movieinfo service in IDE

Open the file MIRest.conf in your IDE. Change the flag ‘VERSION’ from ‘v1’ to ‘v2’ and rebuild.


Update details service mock in API Studio

We are going to update the mock response for the details service in the API Studio, and use the updated mock to serve the modified minfo/listmovies API. Having the entire trace of the request makes it easy to update the upstream service mocks.

  • Click on the details service in the trace on the left-hand side. You should now see the request to the details service, and the corresponding response in the API editor.
  • Add a line to the response on the left-hand side: “country”: “england”. It does not matter where the item is added in the response. Just make sure that the response is still a valid json format.

Save updated trace to a collection

Now save the updated response to a collection for API Studio to generate the mock.

  • Click the Save button.
  • You will have to create a collection if you do not have any existing collections. Name the collection movieinfo. Create the collection, and then save the trace to the collection. When the trace is saved to a collection, Mesh Dynamics automatically creates mocks for all egress requests.

Configure egress request to use mock service

Next, change the egress service configuration for the details service to use the mock you created instead of using the service in the cloud. You can choose to either mock the other services, or continue to use the live services for those requests.

  • Click on the gear icon and select the DevCluster service configuration.
  • Check the Mock box for the details service. Then click the Update button to save the configuration.

Run request using new configuration

  • Make sure that DevCluster is selected as the service configuration in the dropdown.
  • Click the Run button to send the request to the service in the IDE. After the request executes, the results will be populated in the right hand side of the tab.
  • Compare the results from the original service with the new results using the Diff button. You will see that the modified code took the country field from the updated mock service (details) and added that to the bookinfo object returned by the listmovies API.

That's the end of the short introduction to the API Studio. In the subsequent articles, we will get into more specific capabilities and use cases.

Next steps

We will go over some of the common uses of the API Studio.

How did we do?