FormatterHQ

cURL to PHP Guzzle Converter

Turn a curl command into a Guzzle request that uses the right request options (json, form_params, multipart, query and auth) instead of a raw body string.

Input SHELL
Output PHP
Ready.

How to use the cURL to PHP Guzzle Converter

  1. Paste your curl command into the input panel.
  2. The Guzzle code is generated automatically; click Convert after edits.
  3. Install Guzzle with composer require guzzlehttp/guzzle if your project does not have it.
  4. Copy the code into your script or service class and run it.

Convert curl to Guzzle request options

This curl to Guzzle converter translates a curl command into PHP code for GuzzleHttp\Client. Rather than dumping everything into a raw body, it picks the Guzzle request option that matches your data: json for JSON payloads, form_params for URL-encoded forms, multipart for file uploads and query for the query string. The result is shorter and easier to maintain than the equivalent curl_setopt code.

Example: form post

curl -d 'name=Ann&age=31' https://api.example.com/login becomes:

$client = new Client([
    'allow_redirects' => false,
]);

$response = $client->request('POST', 'https://api.example.com/login', [
    'form_params' => [
        'name' => 'Ann',
        'age' => '31',
    ],
]);

Because the command used a bare -d with key=value pairs, the body is decoded into a form_params array. Guzzle re-encodes it and sets the application/x-www-form-urlencoded header for you.

Option mapping

  • JSON: a JSON body with a JSON Content-Type turns into a PHP array under 'json'; the duplicate Content-Type header is dropped.
  • Query string: parameters in the URL move to 'query', and the URL is shortened to its path. When a key repeats (?tag=a&tag=b), the full URL is kept instead.
  • Uploads: each -F field becomes a multipart entry, with files opened by fopen($path, 'r'); -T file becomes a PUT with 'body' => fopen('file', 'r').
  • Auth: -u user:pass maps to 'auth' => [user, pass].
  • Client options: -m sets 'timeout', --connect-timeout sets 'connect_timeout', -k sets 'verify' => false, and a missing -L adds 'allow_redirects' => false, because Guzzle follows redirects by default.
  • Compression: --compressed adds 'decode_content' => true and an Accept-Encoding: gzip, deflate header.

Limitations

Any other body, such as XML or text, is passed through as 'body'. Proxy flags (-x) and other unsupported options like --cert are not converted; each one appears as a comment right after the <?php tag. Guzzle also throws a ClientException or ServerException for 4xx and 5xx responses by default; set 'http_errors' => false if you want to inspect them like curl does.

Headers are written as an associative array, so you can merge them with defaults set on the client through the 'headers' constructor option, which is handy when many requests share one bearer token.

Working in Laravel? The Http facade wraps Guzzle, so the same options apply, for example Http::withBasicAuth() or Http::asForm()->post().

Privacy

The conversion runs in your browser, and tokens or passwords in the command are never uploaded. If you would rather use the native cURL extension, try curl to PHP. You can also test the endpoint first in the API tester.

Frequently asked questions

Which Guzzle version does the code target?
The output uses $client->request() with request options, which works in Guzzle 6 and 7. Guzzle 7 is the version installed by default with Composer on current PHP releases.
How do I use this in Laravel?
You can run the Guzzle code as is, since Laravel includes Guzzle. Or rewrite it with the Http facade, for example Http::withToken($token)->post($url, $data), which sends JSON by default.
Why does Guzzle throw an exception on a 404 response?
Guzzle's http_errors option is on by default, so 4xx and 5xx responses raise exceptions. Catch GuzzleHttp\Exception\RequestException, or pass 'http_errors' => false to handle the status code yourself.
How do I decode the JSON response?
Call json_decode((string) $response->getBody(), true) to get an associative array. Casting the body to a string reads the whole stream.
When does the converter use form_params instead of body?
It uses form_params when the data is simple key=value pairs sent without an explicit Content-Type, which is how curl's -d behaves. JSON, XML or data with a custom Content-Type stays in json or body.

Last updated October 3, 2026

Guides

Related tools

cURL to Axios (Node.js) Converter Convert curl commands to Node.js axios requests with params, headers, JSON data, auth, form-data uploads and timeouts. cURL to C# Converter Convert curl commands to C# HttpClient code for .NET with headers, content types, basic auth, multipart and TLS options. cURL to Go Converter Convert curl commands into Go code using net/http — method, headers, JSON or form body, basic auth, timeouts and multipart uploads. cURL to Java Converter Convert curl commands to Java 11+ java.net.http.HttpClient code with headers, body, redirects and timeouts. cURL to JavaScript Fetch Convert curl commands into JavaScript fetch() code with method, headers, JSON body, form data, basic auth and timeouts. cURL to PHP Converter Convert curl commands into PHP code using the curl_* functions: method, headers, body, auth, cookies and SSL options. cURL to Python Requests Convert curl commands into Python requests code: headers, params, JSON or form data, files, cookies, auth and timeouts. cURL to Rust Converter Convert curl commands to Rust using the reqwest crate, with JSON bodies via serde_json, headers, auth and timeouts. Date & Time Calculator Calculate the difference between two dates or add/subtract days, weeks, months and years from a date. Docker Run to Docker Compose Convert one or more docker run commands into a docker-compose.yml: ports, volumes, env, restart, networks, healthchecks and more. File Type Checker Find out what a file really is from its content, not its name. Detects 150+ formats and warns when the extension does not match. HTTP Status Codes Searchable list of the HTTP status codes in use, from 100 to 511, with a plain explanation of when each response is used.