APISIX API Versioning Guide

Introduction

API versioning is crucial for maintaining backward compatibility while evolving your APIs. APISIX provides multiple strategies for implementing API versioning effectively.

Prerequisites:
  • APISIX installed and configured
  • Basic understanding of HTTP routing
  • Knowledge of APISIX route configurations

URI-based Versioning

Path-based Version Control

{
    "uri": "/v1/users/*",
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "backend-v1:8080": 1
        }
    }
}

{
    "uri": "/v2/users/*",
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "backend-v2:8080": 1
        }
    }
}

Header-based Versioning

Custom Header Version Control

{
    "uri": "/users/*",
    "vars": [
        ["http_api_version", "==", "v1"]
    ],
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "backend-v1:8080": 1
        }
    }
}

Content Negotiation

Accept Header Versioning

{
    "uri": "/users/*",
    "vars": [
        ["http_accept", "==", "application/vnd.company.api-v1+json"]
    ],
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "backend-v1:8080": 1
        }
    }
}

Advanced Version Routing

Multiple Version Support

{
    "uri": "/users/*",
    "plugins": {
        "traffic-split": {
            "rules": [
                {
                    "match": [
                        {
                            "vars": [
                                ["http_api_version", "==", "v2"]
                            ]
                        }
                    ],
                    "weighted_upstreams": [
                        {
                            "upstream": {
                                "type": "roundrobin",
                                "nodes": {
                                    "backend-v2:8080": 1
                                }
                            },
                            "weight": 100
                        }
                    ]
                }
            ]
        }
    }
}

Version Deprecation

Managing API Lifecycle

{
    "uri": "/v1/*",
    "plugins": {
        "response-rewrite": {
            "headers": {
                "Deprecation": "true",
                "Sunset": "Sat, 31 Dec 2023 23:59:59 GMT",
                "Link": "; rel=\"successor-version\""
            }
        }
    }
}

Best Practices

Versioning Guidelines

  • Choose a consistent versioning strategy
  • Document version changes clearly
  • Maintain backward compatibility
  • Plan for version deprecation
  • Monitor version usage

Read Next

Performance Tuning

Optimize your APISIX gateway performance

Read More

Traffic Splitting

Learn about traffic management

Read More