ARTICLE - Backend Integration

API Versioning and Security Basics: Authentication, Rate Limiting, and HTTPS

How do you change an API without breaking existing users? This guide compares URL vs Header versioning and API Key vs Basic Auth vs OAuth2, explains rate limiting, and why HTTPS is a must.

2026-08-12 16IDC Original

API Versioning and Security Basics: Authentication, Rate Limiting, and HTTPS

Once an API goes live, other programs start calling it. If you rename a field or change the response format, every old caller may break. So "how to evolve after launch" and "how to prevent abuse" are the two required lessons of API design. This article covers versioning, authentication, rate limiting, and HTTPS.

1. Why Versioning Matters

Software evolves, and so do APIs — but callers cannot upgrade at the same pace. Versioning adds a "compatibility layer": old and new versions coexist, old users keep using v1, new features ship in v2, and everyone gets what they need without breaking anyone.

Suppose your order API needs to change from "return the whole order" to "paginated results". Changing it directly would break old callers. The right move is to release a v2, let old callers keep using v1, and only take v1 down after they migrate. A typical migration window is 6-12 months.

2. Two Main Versioning Approaches

1. URL path versioning: put the version in the path, e.g. https://api.example.com/v2/orders. It is intuitive and cache-friendly, but one URL maps to only one version. This is the default choice for most teams.

2. Header versioning: put the version in a header, e.g. Accept: application/vnd.example.v2+json. The URL stays clean, but it is harder to debug and cache, and operators cannot see the version at a glance.

Comparison:

Aspect URL Path Versioning Header Versioning
Readability High, visible at a glance Low, hidden in a header
Cache-friendly Yes No
Ease of use Simple More complex
When to use Default for most teams When a clean URL is a priority

Either way the core rule is the same: once v1 ships, never delete or mutate it — only add, and announce removals well in advance. For full API design rules, see RESTful API Design Best Practices.

3. Comparing Three Authentication Methods

Not just anyone should be able to call your API. You need to prove "who you are and what you may do". The three most common authentication methods:

Method How It Works Pros Cons Best For
API Key A secret key sent with each request Simple, fast to adopt Keys can leak; hard to revoke one user Internal tools, server-to-server
Basic Auth username:password Base64-encoded Minimal, browser-native Plaintext by design, needs HTTPS Temporary debugging
OAuth2 An authorization server issues a token Fine-grained scopes, revocable, mature standard Complex; needs an authorization server Third-party user-facing apps

Key point: API keys and Basic Auth were never designed for secure transport — the credential is essentially a plaintext "key". They must be paired with HTTPS, otherwise the key is hanging on the front door. For user-facing login and authorization, prefer OAuth2. See API Security with OAuth/JWT and JWT Authentication Implementation Guide.

4. Rate Limiting: A Faucet for Your API

Rate limiting controls how many requests are allowed per time window, preventing a single caller from overwhelming your server. It is also one of the most effective ways to stop malicious scraping. A common implementation is the token bucket: a fixed number of "tokens" is added each second, one token is consumed per request, and once the bucket is empty new requests are rejected.

A typical config: 60 requests per minute per user (1 per second). Beyond that, return 429 Too Many Requests and tell the caller when to retry (e.g. Retry-After: 30). A sensible rate limit reduces the chance of being knocked over and helps control cost.

5. HTTPS: A Must for APIs

HTTPS has been mentioned repeatedly, and it is not a "suggestion" but a "requirement". Three reasons: it prevents data from being read in transit (passwords, tokens, order details); it prevents content from being tampered with; and many browsers and systems block non-HTTPS endpoints outright. For how HTTPS and certificates work, see What Is HTTPS. Authentication, rate limiting, and encryption together make a secure API — see also Web Security Hardening Guide.

  • When can I finally take v1 down:Track v1 traffic. When it has been near zero for 1-2 months and you have announced the shutdown on your site for at least 30 days, you can consider it.
  • My API key leaked, what now:Revoke it and generate a new one immediately, then check access logs for any abnormal calls before the leak. Always keep keys in server-side environment variables, never in frontend code.
  • Won't rate limiting hurt legitimate users:It can, so leave headroom — set the threshold at roughly 2-3x your peak call rate — and give callers a clear 429 message plus a retry mechanism.
  • Do small projects need OAuth2:Not necessarily. If it is two services within your own product, API Key + HTTPS is enough. You only need OAuth2 when third parties must log in to your platform.

7. Summary

One line: versioning protects old users, authentication decides who gets in, rate limiting stops you being hammered, and HTTPS secures the transport. Do all four and your API is ready to face the public. For more, bookmark the Backend Integration category.

Integration & Code Examples

Example 1: Run v1 and v2 side by side with an explicit sunset

# Version plus deprecation metadata: old clients keep working while migration happens
from datetime import datetime, timedelta, timezone
from fastapi import FastAPI, Response

app = FastAPI()
SUNSET = (datetime.now(timezone.utc) + timedelta(days=180)).strftime("%a, %d %b %Y %H:%M:%S GMT")

@app.get("/v1/orders")
def list_orders_v1(response: Response):
    response.headers["Deprecation"] = "true"
    response.headers["Sunset"] = SUNSET                                  # RFC 8594
    response.headers["Link"] = '</v2/orders>; rel="successor-version"'
    return {"items": [], "next": None}          # old shape: whole list, no pagination

@app.get("/v2/orders")
def list_orders_v2(page: int = 1, size: int = 20):
    return {"items": [], "page": page, "size": size, "total": 0}          # new shape: paginated

Give callers at least one full business cycle, and publish the sunset date with the successor endpoint — otherwise clients only move when they break.

Example 2: Enforce HTTPS and rate limits at the edge

# Two baseline protections: encrypted transport and per-client rate limiting
limit_req_zone $binary_remote_addr zone=api_per_ip:10m rate=20r/s;

server {
    listen 443 ssl;
    http2 on;
    server_name api.example.com;

    ssl_certificate     /etc/letsencrypt/live/api.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    location / {
        limit_req zone=api_per_ip burst=40 nodelay;
        limit_req_status 429;
        add_header Strict-Transport-Security "max-age=31536000" always;
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

server {
    listen 80;
    server_name api.example.com;
    return 301 https://$host$request_uri;      # port 80 only redirects
}

With multiple instances, move rate limiting to the gateway or a Redis counter; per-node limit_req only stops floods on one node.

Four Checks Before Retiring an API Version

Retiring v1 takes more than an announcement. Four checkpoints each carry a measurable criterion, and missing one leaves a caller blocking the shutdown at the last minute.

Checkpoint Criterion Figure used in this guide
v2 shipped Old and new run in parallel; v1 is add-only v1 is never deleted, only announced before removal
Response headers Deprecation, Sunset and Link rel="successor-version" all present Sunset states the retirement date per RFC 8594
Notice period Replacement endpoint and date published At least 30 days
Traffic criterion v1 call volume near zero For 1–2 consecutive months
Migration window Total time granted to callers 6–12 months

The order is: mark, announce, then read the traffic numbers. All three satisfied before shutdown; announcing without reading traffic bets that every caller reads release notes.

Two threshold sets travel with those checks: rate limiting starts at 60 requests per user per minute (1 per second) and moves to 2–3x peak volume when legitimate traffic is blocked; the entry point serves TLS 1.2 and 1.3 only, sends port 80 to HTTPS with a 301 site-wide, and returns HSTS max-age=31536000. These values belong in gateway config, where they cannot be forgotten, rather than in a document.

Limitations

  • Software evolves, and so do APIs — but callers cannot upgrade at the same pace.
  • They must be paired with HTTPS, otherwise the key is hanging on the front door.
  • Give callers at least one full business cycle, and publish the sunset date with the successor endpoint — otherwise clients only move when they break.

FAQ

What does OAuth2 require before integration?

You need an authorization server first; the client only carries tokens and never touches user passwords. Self-hosting means evaluating something like Keycloak, while a managed authorization service removes the ops load. Without one, an API key plus HTTPS covers internal calls; reserve OAuth2 for third-party login on your platform.

What order do you handle a leaked API key in?

Revoke first, rebuild second — never the reverse. Kill the old key in the console, generate a new one, and inject it into the server through environment variables. Then read the access logs for unusual calls and unknown source IPs between leak and revocation; hard-coded frontend keys are the usual cause. Review rotation every 90 days.

Why do callers keep getting 429 responses?

Check the caller's own quota first, then the server-side threshold. A typical setup allows 60 requests per user per minute, returns 429 past that, and states the wait in Retry-After; callers should back off by that value instead of retrying at once. If legitimate traffic gets blocked, raise the threshold to 2–3x peak volume.

When do you need OAuth2 instead of an API key?

Use OAuth2 for third-party authorization on behalf of end users, and an API key over HTTPS for service-to-service calls. OAuth2 tokens support fine-grained scopes and individual revocation, at the cost of running an authorization server; API keys are simple but hard to revoke one by one, so a leak forces a full reissue. Basic Auth is only for temporary debugging.

Related Providers

  • Postman: Use it when v1 and v2 need separate saved collections for regression runs.
  • curl: Use it when tracing whether a 401 or 429 comes from auth headers or rate limits.
  • Cloudflare: Use it when rate limits and bot rules must sit in front of the API host.

Community & Resources

Communities and official channels

Learning resources and tools

Original source: 16IDC Original ↗