Working with API Templates using the Template Designer
Last updated: 6 minutes read.
API Templates are an API governance feature provided to streamline the process of creating Tyk OAS APIs. An API template is an asset managed by Tyk Dashboard that is used as the starting point - a blueprint - from which you can create a new Tyk OAS API definition.
The Tyk Dashboard UI provides the following functionality to support working with API templates:
- Creating templates
- Using templates
- Managing templates
API Templates can be found in the API Templates section of the API Management menu in the Tyk Dashboard. This screen lists all the templates currently registered with Tyk and displays their names and short descriptions. It also gives access to options to create and manage templates.
Note
API Templates are exclusive to Tyk OAS APIs.
Creating templates
API templates can be created starting from a blank template or from an existing API
Creating a new API template
To create a template, simply visit the API Templates section of the Tyk Dashboard and select ADD TEMPLATE.
This will take you to the Create API Template screen, where you can configure all aspects of the template.
The template does not need to be a complete or valid API definition however as a minimum:
- you must give the template a Name
- you must give the template a Description
In this example, we have configured just the Name, Description, Gateway Status and Access settings:
When you have configured all of the API-level and endpoint-level settings you require, select SAVE TEMPLATE to create and register the template with Tyk.
Returning to the API Template screen you will see your new template has been added to the list and assigned a unique id
that can be used to access the template from the Tyk Dashboard API:
Creating a template from an existing API
You can use an existing API deployed on Tyk as the basis for a new API template - this is a great way to build up a portfolio of standardized APIs once you’ve got your first one correctly configured.
From the Created APIs screen within the APIs section of the Tyk Dashboard, select the API that you wish to use as your starting point. In the ACTIONS drop-down select the CREATE API TEMPLATE option.
This will take you to the Create API Template screen, where you can configure all aspects of the template.
The template does not need to be a complete or valid API definition however as a minimum:
- you must give the template a Name
- you must give the template a Description
In this example, we have configured the Name and Description. The base API included response header transformation middleware on the /anything
endpoint and API-level cache configuration, all of which will be configured within the template.
When you have configured all of the API-level and endpoint-level settings you require, select SAVE TEMPLATE to create and register the template with Tyk.
Returning to the API Template screen you will see your new template has been added to the list and assigned a unique id
that can be used to access the template from the Tyk Dashboard API.
Using templates
API templates are used as the starting point during the creation of a new API. They can be applied in all of the methods supported by Tyk for creating new APIs.
Using a template when creating a new API
There are two ways to base a new API, created entirely within the Tyk Dashboard’s API Designer, on a template that you’ve created and registered with Tyk.
You can go from the API Template screen - for the template you want to use, select CREATE API FROM TEMPLATE from the ACTIONS menu:
Or, from the Created APIs screen, select ADD NEW API as normal and then select the template you want to use from the API Template section:
Both of these routes will take you through to the API Designer, where the settings from your API template will be pre-configured.
In this example, we applied “My first template” that we created here. You can see that the Gateway Status and Access fields have been configured:
Using a template when importing an OpenAPI description or API definition
From the Import API screen, if you select the OpenAPI type then you can create an API from an OpenAPI description or Tyk OAS API definition; choose the appropriate method to provide this to the Dashboard:
- paste the JSON into the text editor
- provide a plain text file containing the JSON
- provide a URL to the JSON
After pasting the JSON or locating the file, you can select the template you want to use from the API Template section:
In this example we used this simple OpenAPI description and selected “My second template” that we created here:
|
|
The API that is created has both /xml
and /anything
endpoints defined, with API-level caching configured. You can see the API definition here.
Managing templates
The Dashboard UI allows you to edit and delete templates after they have been created and registered with the Tyk Dashboard
Editing a template
You can make changes to a template that has been registered with Tyk from the API Templates screen. For the template that you want to modify, simply select EDIT TEMPLATE from the ACTIONS menu:
This will take you to the API Template Details screen where you can view the current template configuration. If you want to make changes, simply select EDIT to make the fields editable:
Alternatively you can view and modify the raw JSON for the template by selecting VIEW RAW TEMPLATE from the ACTIONS menu:
You’ll need to select SAVE TEMPLATE to apply your changes from either screen.
Deleting a template
You can delete a template from your Tyk Dashboard from the API Template Details screen. This screen can be accessed by selecting the template from the API Templates screen (either by clicking on the template name, or selecting EDIT TEMPLATE from the ACTIONS menu):
From the API Template Details screen you can select DELETE TEMPLATE from the ACTIONS menu:
Note
You will be asked to confirm the deletion, because this is irrevocable. Once confirmed, the template will be removed from the database and cannot be recovered.