What is CI4's approach to API versioning?

Why Interviewers Ask This

Advanced questions like this reveal whether a candidate has internalized CodeIgniter deeply enough to make architectural decisions. Strong answers demonstrate both breadth and depth of experience.

Answer

API versioning in CodeIgniter 4 is typically handled through route prefixing and namespacing. Define versioned routes: $routes->group("api/v1", ["namespace" => "App\Controllers\Api\V1"], function($routes) { $routes->resource("users"); }) and $routes->group("api/v2", ["namespace" => "App\Controllers\Api\V2"], function($routes) { $routes->resource("users"); }). Create controllers in corresponding namespace directories: app/Controllers/Api/V1/UserController.php. Each version can have its own controller logic, models, and response format. Alternatively, use headers for versioning (Accept: application/vnd.myapi.v2+json) and handle version selection in a filter or base controller. Share common logic through a base API controller that versioned controllers extend. Consider maintaining only the latest two API versions and deprecating older ones with sunset headers.

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real CodeIgniter project.