What is REST API versioning, and what are the ways to implement it?

REST API Versioning is a technique used to manage changes in an API without breaking existing client applications. As APIs evolve, new features, request formats, or response structures may be introduced. Versioning allows multiple API versions to coexist so that existing consumers can continue using older versions while newer clients adopt the latest version.

Key Points

Why Do We Need API Versioning?

Consider an API

GET /employees

Version 1 Response

{

"id": 101,

name": "John

}

Later, a new requirement adds email information.

Version 2 Response

{

"id": 101,

"name": "John",

email": "john@example.com

}

Without versioning

Versioning solves this problem by allowing both versions to remain available.

Common API Versioning Approaches

1. URI Versioning (Most Common)

The version number is included in the URL path.

Example

GET /api/v1/employees

GET /api/v2/employees

Advantages

Spring Boot Example

@GetMapping("/api/v1/employees")
public List<Employee> getEmployeesV1() {

    return employeeService.getEmployees();
}

2. Request Parameter Versioning

The version is passed as a query parameter.

Example

GET /employees?version=1

GET /employees?version=2

Advantages

Disadvantages

Spring Boot Example

@GetMapping(

value = "/employees",

params = "version=1"

)
public String getEmployeesV1() {

    return "Version 1";
}

3. Custom Header Versioning

The client specifies the API version using a custom HTTP header.

Example

GET /employees

Header

X-API-VERSION: 1

Advantages

Disadvantages

Spring Boot Example

@GetMapping(

value = "/employees",

headers = "X-API-VERSION=1"

)
public String getEmployeesV1() {

    return "Version 1";
}

4. Media Type (Content Negotiation) Versioning

The API version is specified in the Accept header.

Example

GET /employees

Header

Accept: application/vnd.company.v1+json

or

Accept: application/vnd.company.v2+json

Advantages

Disadvantages

Spring Boot Example

@GetMapping(

value = "/employees",

produces =

    "application/vnd.company.v1+json"
)
public Employee getEmployeeV1() {

    return employee;
}

Comparison of Versioning Approaches

URI Versioning

Request Parameter Versioning

Custom Header Versioning

Media Type Versioning

Example

Suppose an e-commerce application exposes

Version 1

GET /api/v1/products

Returns

Product Name

Price

Version 2

GET /api/v2/products

Returns

Product Name

Price
Category
Rating

Older mobile applications continue using v1 while newer applications consume v2.

This ensures smooth upgrades without service disruption.

Best Practice

For most enterprise applications and interviews

URI Versioning

Example

/api/v1/employees

/api/v2/employees

is the most commonly preferred approach because it is simple, explicit, and easy to maintain.

Real-World Example

Popular companies use API versioning extensively

This allows them to introduce new features without breaking existing integrations.

Interview Tip

A concise interview answer is

REST API versioning is a strategy used to manage API changes while maintaining backward compatibility for existing clients. Common versioning approaches include URI versioning (/api/v1/resource), request parameter versioning (?version=1), custom header versioning (X-API-VERSION), and media type versioning using the Accept header. Among these, URI versioning is the most widely used due to its simplicity and clarity.

Last updated: 11 November 2026

Previous question: How do you create a REST API in Spring Boot?

Next question: What are REST API best practices?

More Spring Boot - Level I interview questions

All Spring Boot - Level I questions