Skip to content

cURL to Laravel Http

Convert a curl command into Laravel's Http facade call, with headers, query, body and basic auth carried over as a fluent chain, 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 Laravel Http converter

Paste a curl command and get a call to Laravel's Http facade: method, URL, query string, headers, body and basic auth carried over as a fluent chain, with a JSON body read into a real PHP array rather than a string. This page is the Laravel Http output of the cURL to Code studio; fetch, Axios and Guzzle 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 Illuminate\Support\Facades\Http;

$headers = [
    'accept' => 'application/json',
    'content-type' => 'application/json',
    'authorization' => 'Bearer abc.def.ghi',
];

$query = [
    'active' => 'true',
];

$body = [
    'name' => 'Ada Lovelace',
    'role' => 'admin',
];

$response = Http::withHeaders($headers)
    ->withQueryParameters($query)
    ->post('https://api.example.com/v1/users', $body);

The accept/content-type headers already say the request is JSON, so $body is a plain PHP array that Laravel's Http client will encode and send as JSON itself, rather than a pre-encoded string.

How to use it

  1. Paste a curl command, drop a file, or load an example.
  2. Turn on Throw on 4xx/5xx if you want a failed response to throw.
  3. Copy or download the generated file.

Frequently asked questions

Why are the headers, query and body built as separate variables?
It reads better than an array literal nested three levels deep inside a fluent chain, and it's easy to edit any one of them without touching the chain itself. The variables are named $headers, $query and $body and are always defined right above the call that uses them.
What if the curl method has no matching Http method?
Http::get, ->post, ->put, ->patch, ->delete, ->head and ->options cover the common verbs. For anything else (a custom verb such as PURGE), the generated code falls back to Http::send('VERB', $url, $body), which Laravel's Http client supports directly; a diagnostic explains why.
Does it add error handling?
Only if you turn on the Throw on 4xx/5xx option, which appends ->throw() to the chain, matching Laravel's own opt-in behaviour. Off by default, since not every caller wants an exception on a 4xx/5xx response.