expiration
(expires
for Tyk Classic APIs), after which the API will no longer be available. If this is left blank then the API version will never expire. This is configured in standard ISO 8601 format.
When sunsetting API versions, you may have endpoints that become deprecated between versions. It can be more user friendly to retain those endpoints but return a helpful error, instead of just returning HTTP 404 Not Found
.
This is easy to do with Tyk. You could, for example, include the deprecated endpoint in the new version of the API and configure the mock response middleware to provide your clients with relevant information and instruction. Alternatively, you could return a HTTP 302 Found
header and redirect the user to the new endpoint.
/my-api/v1/users
) is a widely used approach recognized in many API designs. The version identifier is clearly visible in the request and, with the unique URL, can simplify documentation of the different versions. Tyk can support the version identifier as the first URL fragment after the listen path, such that the request will take the form <listenPath>/<versionIdentifier>/<endpointPath>
.
/my-api/users?version=v1
) is easy to implement and understand. The version identifier is clearly visible in the request and can be easily omitted to target a default version. Many analytics tools can parse query parameters, making this a very analytics-friendly approach to versioning.
x-api-version:v1
) keeps the URL clean, which can be aesthetically pleasing and easier to read. It works well with RESTful design principles, treating the version as metadata about the request and allows for flexibility and the ability to make changes to the versioning scheme without modifying the URL structure. Headers are less visible to users than the request path and parameters, providing some security advantage. Be aware that other proxies or caches might not consider headers for routing, which could bring issues with this method.
upstream.url
(target_url
for Tyk Classic APIs) with the full request path unless configured otherwise (for example, by using the strip listen path feature).
If the version identifier is in the request URL then it will be included in the upstream (target) URL. If you don’t want to include this identifier, then you can set stripVersioningData
(strip_versioning_data
for Tyk Classic APIs) and Tyk will remove it prior to proxying the request.
listenPath
(listen_path
for Tyk Classic APIs) will be deleted prior to creating the proxy URL. If the request does not include a versioning identifier and Tyk is configured to fallback to default, this may lead to undesired behaviour as the first URL fragment of the endpoint will be deleted.
In Tyk 5.5.0 we implemented a new configuration option urlVersioningPattern
(url_versioning_pattern
for Tyk Classic APIs) to the API definition where you can set a regex that Tyk will use to determine whether the first URL fragment after the listenPath
is a version identifier. If the first URL fragment does not match the regex, it will not be stripped and the unaltered URL will be used to create the upstream URL.
HTTP 404 This API version does not seem to exist
. Optionally, Tyk can be configured to redirect these requests to the default version by configuring the fallbackToDefault
option in the API definition (fallback_to_default
for Tyk Classic APIs).
versioning
object to the info
section in the Tyk Vendor Extension. This is where you will configure all the settings for the versioned API. The child APIs do not contain this information.
Note that any version (child or Base) can be set as the default version.
Tyk Classic APIs do not have the base and child concept because all versions share an API definition.
access_rights
assigned in the access keys/tokens or security policies that are applied to keys.
This means that you could restrict client access to only the Base API, while allowing developers to create and test new versions independently. These will only be added to the “routing table” in the Base API when the API owner is ready and access keys could then be updated to grant access to the new version(s).
Note that an access key will only have access to the default
version if it explicitly has access to that version (e.g. if v2
is set as default, a key must have access to v2
to be able to fallback to the default if the versioning identifier is not correctly provided in the request.
When using Tyk OAS APIs each version of the API has a unique API Id, so you simply need to identify the specific versions in the access_rights
list in the key in the same way that you would add multiple different APIs to a single key.
versions
list in the key within the single entry for the API in the access_rights
list.
Feature | Configurable in Tyk OAS versioning | Configurable in Tyk Classic versioning |
---|---|---|
Client-Gateway security | ✅ | ❌️ |
Request authentication method | ✅ | ❌️ |
API-level header transform | ✅ | ✅ |
API-level request size limit | ✅ | ✅ |
API-level rate limiting | ✅ | ❌️ |
API-level caching | ✅ | ❌️ |
Endpoints (method and path) | ✅ | ✅ |
Per-endpoint middleware | ✅ | ✅ |
Context and config data for middleware | ✅ | ❌️ |
Custom plugin bundle | ✅ | ❌️ |
Upstream target URL | ✅ | ✅ |
Gateway-Upstream security | ✅ | ❌️ |
Traffic log config | ✅ | ❌️ |
API segment tags | ✅ | ❌️ |
info.versioning
object to the Tyk Vendor Extension.
Some notes on this:
self
as the identifier in the default
fieldversions
field you must provide a list of key-value pairs containing details of the child versions:
id
: the unique API Id (x-tyk-api-gateway.info.id
) assigned to the API (either automatically by Tyk or user-defined during API creation)name
: an identifier for this version of the API, for example v2
versions
list in the base API definition. We strongly recommend, however, that you configure info.state.internal
to true
for all child APIs so that they can only be accessed via the base API.
x-api-version
header to be provided and will invoke a version of the API as follows:
v1
then the Base API will be processedv2
then the request will be forwarded internally to the API with API Id <child-api-id>
default
version will be used (in this instance, the Base API) because fallbackToDefault
has been configureddefault
version (in this instance the Base API)<child-api-id>
.
x-api-version
. You can modify this if required, but if you’re happy with this then that’s it - your new API version is ready for use.
Don’t forget to select Save API.
v1
and v2
):
x-api-version
v1
and v2
v1
and v2
is that v2
will proxy the request to a different upstream via the configured override_target
default_version
) is v1
v3
), it will be directed to the default (fallback_to_default:true
)Default
) version of your API in the Versions List. You can add a new version by providing a version name (which will be the value your clients will need to provide in the version location when calling the API).
You can optionally configure an Override target host that will replace the target path that was set in the base configuration for the version. Note that this is not compatible with Service Discovery or Load Balanced settings.
Select Add to create this new version for your API.
spec.definition
and spec.version_data
.
In the following example:
x-api-version
(comments demonstrate how to configure the alternative version identifier locations)v1
v1
v1
override_target
) is configured for v1
to send requests to http://test.org
info.versioning
section of the Tyk Vendor Extension.
Alternatively, Tyk can look after the linking of base and child versions if you are using the Tyk Dashboard API or Tyk Gateway API to manage your Tyk OAS APIs.
If you are using Tyk Classic, then you should configure versioning within the API definition prior to creating the API.
POST /api/apis/oas
and POST /tyk/apis/oas
endpoints:
base_api_id
: The API ID of the Base API to which the new version will be linked.base_api_version_name
: The version name of the base API while creating the first version. This doesn’t have to be sent for the next versions but if it is set, it will override the base API version name.new_version_name
: The version name of the created version.set_default
: If true, the new version is set as default version.PATCH /api/apis/oas
or PATCH /tyk/apis/oas
endpoints.
x-tyk-version
info.versioning
section of the API definition for the base version as explained previously.