PHP theorytheory 0/50 · 0%
APIs · medium

32. cURL & HTTP Clients

Making outbound HTTP requests.

The cURL extension lets PHP make HTTP requests to external APIs: curl_init() creates a handle, curl_setopt() configures options like URL, method, and headers, and curl_exec() performs the request. curl_close() releases resources afterward.

For JSON APIs, you typically set CURLOPT_POSTFIELDS to a json_encode()'d body, add a Content-Type: application/json header, and decode the response with json_decode().

Check your understanding

  1. 1. Which function actually performs the configured cURL request?

  2. 2. Which option sets the request body for a POST request?