Home

Anypoint Studio API Specification Synchronization

Introduction
Starting from Studio version 7.4, you will be able to import an API specification from Anypoint Exchange and scaffold interfaces. The specification’s RAML file will be added to Studio as a read-only dependency, this will give you better clarity regarding the version management provided by Exchange. One of the most demanded features in Anypoint Studio 7.4 is “API Sync.” This new feature replaces the APIkit with similar functionality that is more in line with an API specification’s lifecycle.
Overview
Create and publish an API
We are following the API design-first approach, so let’s create a simple API which specifies two resources called
/bank/account with GET, POST and DELETE methods.
/bank/account/{accountNumber} with GET, PUT and DELETE methods.
 
Next, we publish this initial version to Exchange.
Once published, the API specification is available in the Exchange (but also in Anypoint Design Center).
Scaffold interfaces in Anypoint Studio
In the previous releases of Anypoint Studio, we were able to import an API specification only from Design Center, however, starting from version 7.4 it’s available to import from Exchange and can be added as a dependency of the project. This is good news because it provides better control over updates, ownership, and versioning of the API’s specification.
Let’s take a look at how this functionality should typically be used in Anypoint Studio.
There are several ways to add an API specification as a dependency to the Mule project:
Ø  Add an API specification while creating a new project. When you create a new project, the dialogue box that pops up, allows you to select the API specification from Exchange or Maven.
Ø  Add an API specification to an existing project. From the context menu select Mule, then select Manage APIs.
Ø  The corresponding pop-up box connects to Exchange and shows the API specifications available.
Once imported, the API specification’s RAML file is added as a dependency to the Studio project. The RAML file will be read-only in Studio and only editable in the Design Center.
Scaffolding will be auto-generated for each endpoint resource specified in the API specification, ready for the developer to create the implementation.
For those who are familiar with the previous version of this feature, you will note that there is no RAML file available for editing in the src/main/resources location. The API specification is now located as a read-only dependency in the project’s Maven repository.
If a new version of the API specification becomes available, it must be published to Exchange before re-importing it into the Studio project. Let’s take a look at how to do this in the following example.
Reimport an updated API specification
In the API specification below, I have added the PATCH /bank/account endpoint and published it to Exchange. You can see the new version is 1.0.1.
Back in Studio, let’s check for possible updates. From the context menu, select API Specs, then the name of the API specification (in this case Mars Delivery), then click Check for Updates.
Anypoint Studio will check Exchange for updated versions of the API specification and present a confirmation to update the current dependency.
Once you accept to update the dependency, the APIs scaffolding will be regenerated from the new API specification and replace the current version. You must now reference the current implementation and add any new functionality that the updated API design specifies.
Conclusion
We will have more control over the API design lifecycle. If you want to edit to the specification you will be able to open it for editing in the design center from within Studio. This ensures that no changes are made to the API specification in the implementation design environment.
Download
S. No
File Name
Size
Download
1
Anypoint Studio API Specification Synchronization.pdf
1.0 MB

Comments