Since the launch of the Integrations feature, the SwaggerHub team has continuously strived to bring the very best tooling to your API projects. While by itself, the SwaggerHub Editor is a powerful tool to both author and visualize your Swagger definition, the design process can be greatly improved if the designer could iterate quickly on how the API actually behaves. Working with both the look and feel of an API from a client’s perspective is the start to building a great API, and our latest Integration allows for exactly that – The Smartbear VirtServer Integration! VirtServer is part of the SmartBear Ready! API virtualization product. The VirtServer Integration in SwaggerHub integrates basic virt functionality directly into the API lifecycle. When enabled, the VirtServer Integration automatically creates and maintains a semi-static mock of an API defined in SwaggerHub. This mock is updated every time you save the API, meaning you no longer have to find and use external tools to create mock services. You can efficiently iterate on the design with your team with the preview generated by the VirtServer, all with a couple of clicks.
Enabling the VirtServer
Just like SwaggerHub’s GitHub Sync or the Webhook Integration, the SmartBear VirtServer Integration can be added to the API from the Manage Integrations option in the top-right corner. The true utility of the SmartBear VirtServer Integration can be realized when you see how easy it is to add and configure the Integration. Here are the fields you can use to optimize the VirtServer to your design needs:
- Name: This is what the specific VirtServer Integration will be called.
- API Token: Once an arbitrary API token is specified and the Integration is enabled, each request to the mock server will need to have this token in the Authorization header. This is available only for Private APIs on SwaggerHub.
- API Token: Once an arbitrary API token is specified and the Integration is enabled, each request to the mock server will need to have this token in the Authorization header. This is available only for Private APIs on SwaggerHub.
- Default Response Content Type: The default response content type the mock would return if this wasn’t specified in the API specification
- Update host setting: Allows the Integration to modify your Swagger spec to update the basePath, host or schemes properties to point to the mock automatically. This allows the editor and interactive UI to call the virtual server directly, as well as configure auto-generated client SDKs to point to the server.
Once the Integration is enabled, the mock is now ready to use!
Generating Multiple Defined Responses
This generated mock will have static responses created for each produces/response-message combination. If an operation has multiple responses, the mock will cycle through them sequentially; for example if an operation has 200, 404 and 500 responses, they will be returned in sequence for that operation. The mock server can be a powerful tool when deliberating on the API design. Without writing a line of code, you can allow API consumers to develop clients against the VirtServer, which is guaranteed to respond with compatible, realistic payloads. More importantly, you can tune the payloads directly in the Swagger Definition by using the “example” construct inside your model definitions. You can read more about how to set the VirtServer Integration from its documentation. This Integration was thanks to the folks at SmartBear Software! Watch for future enhancements in this and other integrations as well. If you have any suggestions for new Integrations or want to see your product integrated with SwaggerHub, give us a shout out with a feature request here.