Importing Swagger API Representations to Create API Monitors

Swagger is an open source project that bills itself as “the World’s most popular framework for APIs”:

Swagger is a simple yet powerful representation of your RESTful API. With the largest ecosystem of API tooling on the planet, thousands of developers are supporting Swagger in almost every modern programming language and deployment environment. With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability.

Swagger’s Getting Started page states that Swagger’s goal “is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.”

If your API has a Swagger representation, then creating a monitor for your API is straightforward, using API Science’s import capability. In this post, I illustrate how to do this, using the Swagger Petstore API representation.

Creating the API Science Monitor

To create a Swagger Petstore API monitor, log into your API Science account, click “Import” at the top of the page, and scroll down to the “Swagger” section:

swagger-import

Click the “Import From Swagger” button, and enter the Swagger Petstore API URL:

swagger-import-url

Clicking the “Import” button embeds the Swagger summary page for the Swagger Petstore API:

swagger-petstore-import

Let’s say your product depends on information about the Pet Store’s pets. Clicking on the pet link displays the available API calls related to pets:

swagger-pet-store-api-calls

Futhermore, let’s say your product depends on getting information about specific pets based on the petID. Clicking on “GET /pet/{petID}” link brings up the details:

swagger-petstore-import-get-petid

 

Entering an integer (for example, 1) into the petId field and clicking the “Try it out!” button produces a result like this:

swagger-petstore-import-get-petid-result

Clicking the “Run on API Science” button creates your new API Science monitor, runs the monitor, and provides you with its URL:

swagger-petstore-import-apiscience-url

Your API Science dashboard now includes the new monitor:

swagger-petstore-api-science-dashboard1

 

Clicking on the monitor name shows you the first result from your new API Science API monitor check:

swagger-petstore-api-science-checks1

 

Conclusion

In a few simple steps, we’ve taken a Swagger API definition and turned it into an API Science monitor. For any API that is a critical component of your product — whether the API is internal or external —  if the API has a Swagger representation, it is possible for you to very easily and quickly create an API Science monitor that checks and logs the API’s current status.

–Kevin Farnham