🔥 CodeIgniter Intermediate

What is the HTTP Client in CodeIgniter 4?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

CodeIgniter 4 includes a built-in HTTP Client (based on cURL) for making outgoing HTTP requests to external APIs. Get it: $client = service("curlrequest"). Make a GET request: $response = $client->get("https://api.example.com/users"). POST with JSON: $client->post($url, ["json" => $data]). With headers: $client->get($url, ["headers" => ["Authorization" => "Bearer " . $token]]). Access response: $response->getStatusCode(), $response->getBody(), $response->getJSON(). Options: timeout, connect_timeout, allow_redirects, verify (SSL). CI4's HTTP client is simpler than Guzzle but sufficient for most API calls. For complex scenarios (connection pooling, async requests), use Guzzle via Composer.

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.