What is CodeIgniter 4's RESTful API support?
Why Interviewers Ask This
This tests whether you can apply CodeIgniter knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
CodeIgniter 4 has built-in support for building RESTful APIs. The ResourceController provides RESTful routing: $routes->resource("users") maps HTTP verbs to controller methods: index() (GET /users), show($id) (GET /users/id), create() (GET /users/new), store() (POST /users), edit($id) (GET /users/id/edit), update($id) (PUT/PATCH /users/id), delete($id) (DELETE /users/id). For APIs (no HTML forms), use $routes->presenter("photos") which excludes create/edit. Return JSON: return $this->response->setJSON(["status" => "success", "data" => $users]). The Content Negotiation feature automatically formats responses based on the Accept header. Use Filters for authentication (JWT tokens, API keys) before resource controllers.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.