← How-to Guides

Generate a collection from an API specification

Uses: Insomnia
TL;DR

Create or import an API spec as a design document and define environment variables, then click settings icon and click Generate collection. Generating a collection from a document allows you to test your requests while still working on the design.

Prerequisites

Insomnia

Download and install Insomnia.

Create an API specification

You can either create an empty document and design your specification from scratch, or import an existing specification. This example uses the Konnect API Products specification.

1. Configure an environment

If your API specification contains variables, you can use the environment to replace them with actual value in all the requests in your collection.

Click Base Environment, then click the pencil icon to open the Manage Environment window and define the environment variables you need. In this example, we need to define at least the base URL and token:

{
	"base_url": "https://us.api.konghq.com/v2",
	"bearerToken": "<my token>"
}

2. Generate a collection

Open your document and click the settings icon next to Preview. Click Generate collection. A collection of requests in created in the COLLECTION tab.

If the operations in the API spec have tags, the requests are organized into folders based on these tags. If an operation has multiple tags, the request is duplicated and appears in each folder. You can reorganize the requests as needed. For more information, see Collections.

Since this collection is linked to a document, it cannot be accessed from the Collections list. You can find it in the COLLECTION tab of your document.

3. Send requests

If the necessary environment variables are set, you can send a request right away. In this example using the Konnect API Products specification, we can send the List API Products request with only the base URL and Bearer token defined:

Insomnia request with 200 status code

Did this doc help?

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!