Tài liệu api
API Documentation (Tài liệu API) là cẩm nang hướng dẫn kỹ thuật chi tiết giúp lập trình viên hiểu cách thức hoạt động, cách kết nối và tích hợp ứng dụng của họ với một API cụ thể. Nó hoạt động giống như một bản menu trong nhà hàng, cho khách hàng (lập trình viên) biết rõ hệ thống đang cung cấp những gì và làm sao để gọi món
$data = [ 'name' => 'John Doe', 'email' => 'john@example.com' ];
Encode array into a JSON string $payload = json_encode($data); // 3. Initialize cURL session $ch = curl_init('https://api.example.com/users'); // 4. Set cURL options curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); // Set application/json headers curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Accept: application/json', // Tells the server you expect JSON back 'Content-Length: ' . strlen($payload) ]); // 5. Execute and capture response $response = curl_exec($ch); // 6. Handle response or errors if ($response === false) { echo 'Error: ' . curl_error($ch); } else { $decodedData = json_decode($response, true); print_r($decodedData); } // 7. Close session curl_close($ch);
16:59:08 30-03-2020
