[{"data":1,"prerenderedAt":66},["Reactive",2],{"/samples/php/guzzle":3,"related:JRahCNLyCz":60},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"link":12,"body":13,"_type":55,"_id":56,"_source":57,"_file":58,"_extension":59},"/samples/php/guzzle","php",false,"","Guzzle","Guzzle is a popular PHP HTTP client library that provides a simple and flexible API for making HTTP requests and handling responses. It offers features like request and response middleware, streaming uploads and downloads, and request batching. Guzzle is widely used for consuming web services, interacting with APIs, and performing HTTP operations in PHP applications.","PHP","guzzle","https://docs.guzzlephp.org/en/stable/",{"type":14,"children":15,"toc":52},"root",[16,31,43],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21,29],{"type":17,"tag":22,"props":23,"children":26},"a",{"href":12,"rel":24},[25],"nofollow",[27],{"type":28,"value":8},"text",{"type":28,"value":30}," is a popular PHP HTTP client library that provides a simple and flexible API for making HTTP requests and handling responses. It offers features like request and response middleware, streaming uploads and downloads, and request batching. Guzzle is widely used for consuming web services, interacting with APIs, and performing HTTP operations in PHP applications.",{"type":17,"tag":32,"props":33,"children":37},"pre",{"className":34,"code":36,"language":5,"meta":7},[35],"language-php","use GuzzleHttp\\Client;\nuse GuzzleHttp\\Exception\\RequestException;\n\nfunction convert($api_key, $params, $endpoint = 'pdf') {\n    // Ensure the endpoint is valid\n    if (!in_array($endpoint, array('pdf', 'png', 'jpg', 'webp'))) {\n        throw new Exception('Invalid endpoint specified');\n    }\n\n    // Set the API URL\n    $url = 'https://api.pdfshift.io/v3/convert/' . $endpoint;\n\n    // Create a Guzzle client\n    $client = new Client();\n\n    try {\n        // Make the POST request\n        $response = $client->post($url, [\n            'headers' => [\n                'Content-Type' => 'application/json',\n                'X-API-Key' => $api_key\n            ],\n            'json' => $params\n        ]);\n\n        // Get the response body\n        $body = $response->getBody()->getContents();\n\n        // Check if filename or webhook were passed\n        if (array_key_exists('filename', $params) || array_key_exists('webhook', $params)) {\n            return json_decode($body, true);\n        }\n\n        // Return the binary content\n        return $body;\n    } catch (RequestException $e) {\n        if ($e->hasResponse()) {\n            $statusCode = $e->getResponse()->getStatusCode();\n            $reasonPhrase = $e->getResponse()->getReasonPhrase();\n            throw new Exception(\"Request failed with status code $statusCode: $reasonPhrase\");\n        } else {\n            throw new Exception(\"Request failed: \" . $e->getMessage());\n        }\n    }\n}\n",[38],{"type":17,"tag":39,"props":40,"children":41},"code",{"__ignoreMap":7},[42],{"type":28,"value":36},{"type":17,"tag":32,"props":44,"children":47},{"className":45,"code":46,"language":5,"meta":7},[35],"try {\n    $result = convert('sk_XXXXXXXXXXXXXX', array(\n        'source' => 'https://en.wikipedia.org/wiki/REST'\n    ));\n\n    var_dump($result);\n} catch (Exception $e) {\n    echo 'Error: ' . $e->getMessage();\n}\n",[48],{"type":17,"tag":39,"props":49,"children":50},{"__ignoreMap":7},[51],{"type":28,"value":46},{"title":7,"searchDepth":53,"depth":53,"links":54},2,[],"markdown","content:samples:php:guzzle.md","content","samples/php/guzzle.md","md",[61,65],{"_path":62,"language":10,"library":63,"_id":64},"/samples/php/curl","curl","content:samples:php:curl.md",{"_path":4,"language":10,"library":11,"_id":56},1785426823423]