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:

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.

API 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:

Configure 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:

Template has been successfully created

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 standardised 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.

Select Create API 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 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.

Configure the template

Cache settings inherited from base API

Endpoint settings inherited from base API

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.

Template has been successfully created

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:

Select Create API from template

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:

Select the template you want to use

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:

The API with template applied

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

    Options when importing an OpenAPI description

After pasting the JSON or locating the file, you can select the template you want to use from the API Template section:

Select the template you want to use

In this example we used this simple OpenAPI description and selected “My second template” that we created here:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "components": {},
  "info": {
    "title": "my-open-api-document",
    "version": "1.0.0"
  },
  "openapi": "3.0.3",
  "servers": [
    {
      "url": "http://httpbin.org"
    }
  ],
  "paths": {
    "/xml": {
      "get": {
        "operationId": "xmlget",
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    }
  }
}

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:

Accessing the API template

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:

Modifying the API template

Alternatively you can view and modify the raw JSON for the template by selecting VIEW RAW TEMPLATE from the ACTIONS menu:

Modifying the API template JSON

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):

Accessing the API template

Accessing the API template

From the API Template Details screen you can select DELETE TEMPLATE from the ACTIONS menu:

Deleting the API template

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.