OpenAPI/Swagger Import
The OpenAPI specification with Swagger tooling is a popular way to document REST APIs. If you’re running an API in production, the chances are pretty good you’re already using it.
If so, Loadster’s OpenAPI Import feature can make creating scripts for your API a lot easier!
It works by letting you browse your API specification and select endpoints, and automatically creating steps for those endpoints in your Loadster script.
Finding the URL to Your API Specification
To import an endpoint from OpenAPI, you’ll need to locate the URL to your API specification.
You may already be familiar with the Swagger UI, which sometimes looks like this:
![The Swagger Petstore Demo API](/img/documentation/openapi-1.jpg)
That URL at the top points to the API specification. The specification is separate from the UI. It’s typically a JSON or YAML file, and it describes each of your API’s endpoints in detail.
Make note of this specification URL, because you’ll need it in order to import your endpoints into Loadster.
Adding an OpenAPI Step to Your Loadster Script
To add an OpenAPI endpoint as a step in your protocol script, choose the Import OpenAPI… option.
![Importing from OpenAPI](/img/documentation/openapi-2.jpg)
In the modal dialog that follows, paste in the URL to your API specification and click Browse.
A list of the API endpoints detailed in that specification will appear. If you have lots of endpoints, you can optionally filter them with a search phrase to find the one you’re interested in.
![Filtering Endpoints from OpenAPI](/img/documentation/openapi-3.jpg)
Select an endpoint and click Add Step.
A new step will appear in your script, pre-populated with the details from the OpenAPI specification. Depending on the completeness of your API specification, you might need to manually edit the body to add specific values for your test.
![Putting General Barkington up for sale in the Petstore! Sorry General...](/img/documentation/openapi-4.jpg)
When Does OpenAPI Import Make Sense?
Creating your Loadster steps directly from OpenAPI is a good idea when your API is already documented that way, and you’re looking to save time as opposed to manually creating steps. It also saves you the trouble of bouncing back and forth between multiple browser tabs to reference your API documentation, since the endpoints are also available to you in Loadster.
Alternatively, if your API is meant to be hit by a web browser (as with a single page web application), then you might save even more time by recording your script with the Loadster Recorder browser extension.
In either case, you can always edit the steps afterwards, for precise control over the requests that Loadster sends to your API.