What are the built-in CodeIgniter 4 Response methods?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for CodeIgniter development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

The Response object in CodeIgniter 4 provides a clean API for building HTTP responses. Access via $this->response in controllers. Set body: $this->response->setBody($html). Set status code: $this->response->setStatusCode(404). Set content type: $this->response->setContentType("application/json"). Set headers: $this->response->setHeader("X-Custom", "value"). Return JSON: return $this->response->setJSON($data) — automatically sets the content type and encodes the array. Return HTML view (shorthand): return view("viewname", $data). Redirect: return redirect()->to("url") or redirect()->route("routename"). Set cookies: $this->response->setCookie("name", "value", 3600). Download: $this->response->download("filename.pdf", $data).

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.