What is the Request object in CodeIgniter 4?

Why Interviewers Ask This

This is a classic screening question for CodeIgniter roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

The Request object provides access to all incoming HTTP request data. Access in controllers via $this->request. GET parameters: $this->request->getGet("name"). POST parameters: $this->request->getPost("name"). Either (GET or POST): $this->request->getVar("name"). All POST data: $this->request->getPost(). JSON body: $this->request->getJSON() (for API endpoints receiving JSON). Request method: $this->request->getMethod(). Check method: $this->request->is("post"). IP address: $this->request->getIPAddress(). User agent: $this->request->getUserAgent(). Headers: $this->request->getHeader("Accept"). Files: $this->request->getFile("avatar"). Server data: $this->request->getServer("SERVER_NAME"). Apply filters to input: $this->request->getPost("name", FILTER_SANITIZE_STRING).

Pro Tip

This topic has CodeIgniter-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.