Skip to content
koducathome

cURL to PHP Requests Converter

Convert curl commands to PHP code using Requests. Paste a command and the Requests snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The PHP Requests code appears instantly; other PHP libraries (cURL, Guzzle) are in the tabs above the code.
  3. Set up: Install with composer require rmccue/requests.
  4. Run it: Run php request.php from the project with the Composer autoloader. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no Requests equivalent.

Example

GET with headers → PHP Requests

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
PHP Requests
<?php

require __DIR__ . '/vendor/autoload.php';

$headers = [
    'Accept' => 'application/json',
    'Authorization' => 'Bearer YOUR_TOKEN',
];

$response = WpOrg\Requests\Requests::request('https://api.example.com/v1/users?page=2', $headers, [], 'GET');

echo $response->status_code . PHP_EOL;
echo $response->body . PHP_EOL;

Common use cases

  • Lightweight PHP projects
  • WordPress-related code

Converting curl to PHP Requests

Requests is a lightweight PHP HTTP library (used by WordPress); version 2 uses the WpOrg\Requests namespace.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent Requests code. Options that have no Requests equivalent are listed under the editors rather than silently dropped.

Other libraries for PHP, each with its own page: cURL, Guzzle.

Limitations

  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

What's WpOrg\Requests?

The namespace of Requests version 2. Older code used the Requests class without a namespace.

Requests or Guzzle?

Requests is smaller and simpler; Guzzle has more features such as middleware and async requests.

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.