Skip to content

cURL to Guzzle

Convert a curl command into a GuzzleHttp\Client request call, with headers, query, body and basic auth carried over as an options array, live in your browser.

Generated files

Generated code appears here.

Diagnostics appear here after you paste your input.

Processed locally in your browser. Your data never leaves your device.

About this curl to Guzzle converter

Paste a curl command and get a GuzzleHttp\Client request call: method, URL, query string, headers, body and basic auth carried over as Guzzle's own options array, with a JSON body read into a real PHP array rather than a string. This page is the Guzzle output of the cURL to Code studio; fetch, Axios and Laravel Http are one click away and use the same parsing.

A worked example

This curl command:

curl 'https://api.example.com/v1/users?active=true' \
  -H 'accept: application/json' \
  -H 'content-type: application/json' \
  -H 'authorization: Bearer abc.def.ghi' \
  --data-raw '{"name":"Ada Lovelace","role":"admin"}'

becomes:

use GuzzleHttp\Client;

$client = new Client();
$response = $client->request('POST', 'https://api.example.com/v1/users', [
    'headers' => [
        'accept' => 'application/json',
        'content-type' => 'application/json',
        'authorization' => 'Bearer abc.def.ghi',
    ],
    'query' => [
        'active' => 'true',
    ],
    'json' => [
        'name' => 'Ada Lovelace',
        'role' => 'admin',
    ],
]);

A file upload field (-F name=@file.png) becomes a multipart entry with fopen(...) in place of the file's contents, since the file was never read; adjust the path before running the code.

How to use it

  1. Paste a curl command, drop a file, or load an example.
  2. Turn on Don't throw on 4xx/5xx if you want to check the status yourself.
  3. Copy or download the generated file.

Frequently asked questions

Why json instead of body for a JSON payload?
Guzzle's json option takes a real PHP value, encodes it and sets the Content-Type header itself, so it's used whenever the curl command's own headers say the body is JSON. Anything else falls back to the body option as a raw string, exactly as curl would have sent it.
How is basic auth represented?
As Guzzle's own auth option, an ['username', 'password'] pair, which Guzzle turns into the same Authorization: Basic header curl's -u/--user would have sent.
Does it add error handling?
Guzzle throws on a 4xx/5xx response by default, matching what's generated. Turn on Don't throw on 4xx/5xx to add http_errors => false instead, if your code checks the status itself.