---
title: "Versioning"
description: "URL path versioning, breaking-change taxonomy, and the deprecation lifecycle."
---

> Documentation Index
> Fetch the complete documentation index at: https://codex.mirio.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Versioning

API versioning is about managing change without breaking clients. The strategy
that causes the least friction: version only when you break something, make
the version visible in the URL, and give clients enough warning to migrate.

## URL path versioning

Include the major version as the first path segment:

```
https://api.example.com/v1/users
https://api.example.com/v1/users/{id}
https://api.example.com/v2/users
```

Alternatives exist: version in the `Accept` header
(`Accept: application/vnd.example.v2+json`) or as a query parameter
(`?version=2`). URL versioning wins on practicality. It's visible in
logs, curl-able without custom headers, bookmark-able, and unambiguous in
access control rules. The trade-off is that it looks "unRESTful"; that's an
acceptable cost.

Only major versions appear in the URL. Minor and patch releases are backward
compatible by definition and don't require a new version segment.

## What counts as a breaking change

If a client written against v1 would break when deployed against the new
version, it's breaking. Everything else isn't.

**Breaking (requires a new major version):**

- Removing a field from a response
- Renaming a field
- Changing a field's type (e.g. `string` → `integer`)
- Changing the semantics of a field (e.g. `status: "active"` now means something different)
- Removing an endpoint
- Removing or renaming a query parameter
- Making a previously optional parameter required
- Changing authentication requirements

**Non-breaking (safe to ship without a version bump):**

- Adding new optional fields to a response
- Adding new endpoints
- Adding new optional query parameters
- Adding new values to an enum (clients must tolerate unknown values)
- Relaxing validation (accepting more inputs than before)

Design clients to be tolerant of additions: ignore unknown fields, handle unknown
enum values gracefully. A strict client that rejects unknown JSON keys will break
on every non-breaking API change.

## Deprecation lifecycle

Don't remove versions without warning. A predictable lifecycle:

1. **Announce** the new version and the deprecation date (minimum 6 months out).
2. **Mark** deprecated responses with the `Deprecation` and `Sunset` headers from day one.
3. **Remove** the version on or after the Sunset date.

### Deprecation and Sunset headers

`Deprecation` (RFC 9745) marks when deprecation began, as a structured-field
date: a Unix timestamp prefixed with `@`. `Sunset` (RFC 8594) marks when the
resource will stop responding, as an HTTP-date. Both are standard headers and
some API clients can surface warnings automatically.

```http
HTTP/1.1 200 OK
Content-Type: application/json
Deprecation: @1735689600
Sunset: Tue, 01 Jul 2025 00:00:00 GMT
Link: <https://api.example.com/v2/users>; rel="successor-version"

{
  "data": { ... }
}
```

The `Link` header with `rel="successor-version"` points clients directly to the
replacement, providing machine-readable migration guidance.

### After the Sunset date

Return `410 Gone` rather than `404 Not Found`. `410` signals permanent removal
and gives clients a clear signal that retrying won't help:

```http
HTTP/1.1 410 Gone
Content-Type: application/json

{
  "error": {
    "code": "API_VERSION_REMOVED",
    "message": "API v1 was removed on 2025-07-01. Migrate to v2: https://docs.example.com/migration/v1-to-v2"
  }
}
```

## Versioning individual endpoints

Sometimes a single endpoint changes semantics while everything else stays stable.
You can version at the resource level instead of the whole API: `/v2/users` while
everything else remains at `/v1/`. This is only worth the operational complexity
if the change is truly isolated and clients need to adopt the resources independently.
For most teams, version the whole API together; partial versioning creates a
combinatorial matrix of tested paths no one wants to maintain.

## New version checklist

Before cutting a new version:

- Document every breaking change with before/after examples
- Provide a migration guide (not only a changelog)
- Set the Sunset date on the old version and add the response headers immediately
- Keep the old version running for at least the promised deprecation window, even if usage drops to near zero
- Monitor version adoption to identify clients that haven't migrated before the Sunset date

Source: https://codex.mirio.dev/web/rest-apis/versioning/index.mdx
