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.
Why Do We Need API Versioning?
GET /employees
{
"id": 101,
name": "John
}
Later, a new requirement adds email information.
{
"id": 101,
"name": "John",
email": "john@example.com
}
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.
GET /api/v1/employees
GET /api/v2/employees
@GetMapping("/api/v1/employees")
public List<Employee> getEmployeesV1() {
return employeeService.getEmployees();
}2. Request Parameter Versioning
The version is passed as a query parameter.
GET /employees?version=1
GET /employees?version=2
@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.
GET /employees
X-API-VERSION: 1
@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.
GET /employees
Accept: application/vnd.company.v1+json
or
Accept: application/vnd.company.v2+json
@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
GET /api/v1/products
Product Name
Price
GET /api/v2/products
Product Name
Price
Category
RatingOlder mobile applications continue using v1 while newer applications consume v2.
This ensures smooth upgrades without service disruption.
Best Practice
URI Versioning
/api/v1/employees
/api/v2/employees
is the most commonly preferred approach because it is simple, explicit, and easy to maintain.
Real-World Example
This allows them to introduce new features without breaking existing integrations.
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?