Last updated: 23 November 2026. Based on the live tool page and Laravel's framework source at version 13.43.0. I could not run the converter itself from my environment, so the code examples below are hand-written equivalents, not tool output. SeeHow this was checked.
API docs, vendor support pages and browser DevTools all hand you a curl command. Your Laravel app needs the same request written with the Http facade. Translating it by hand is easy to get slightly wrong: a missing header, a body sent as form data instead of JSON, a redirect that curl would not have followed. The cURL to Laravel HTTP Client Converter on Dev Talk does that translation in the browser. This article covers what it does, how to use it, and what to check in the generated code before you commit it.
What the tool does
You paste a curl command and it produces Laravel Http:: client code, using helpers such as withToken(), withHeaders(), asForm() and attach(), and ending in the matching get(), post() or put() call. According to the page, it handles tokens, headers, JSON bodies, forms, file uploads and timeouts. The page does not publish a list of supported curl flags, so for anything exotic, read the output rather than assuming it was converted.
What you get on the page:
- A text box for the curl command. Multi-line commands continued with
\(bash),^(Windows cmd) or the backtick (PowerShell) are accepted, as is the output of Chrome's "Copy as cURL". - Code that appears as you type, with a choice of response style:
$response,->json()or->body(). - A toggle for
->throw(), so failed HTTP responses raise an exception. - A checkbox, "Keep browser headers (sec-*, cache-control…)", which controls whether browser-specific headers from a DevTools copy are kept or dropped.
- Examples and Clear buttons, and a "Copy .php" button.
It needs JavaScript. The page says the conversion happens in your browser and that tokens in the command are never uploaded, and the FAQ adds that the command is never sent to Dev Talk's server. I could not verify that independently, so the safe habit stands regardless: if you paste a real token anywhere, rotate it afterwards, and prefer pasting commands with a placeholder.
A typical workflow
- Copy the request. In Chrome or Firefox DevTools, open the Network tab, right-click the request and choose "Copy as cURL". Or take the example from the API's documentation.
- Paste it into the converter. For a DevTools copy, leave the browser-headers checkbox off unless you actually need headers like
sec-fetch-*orcache-control. A server-to-server call does not need them. - Pick the response style and decide whether you want
->throw(). - Copy the code into a service class, not a controller, and replace the token with a config value.
What the output should look like
The tool's own examples are not shown on the page, so here is a hand-written conversion of the kind it produces. This curl command:
curl -X POST https://api.example.com/v1/orders \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"sku":"A-100","qty":2}'
maps to this Laravel code:
<?php
use Illuminate\Support\Facades\Http;
$response = Http::withToken(config('services.shop.token'))
->acceptJson()
->post('https://api.example.com/v1/orders', [
'sku' => 'A-100',
'qty' => 2,
]);
$order = $response->json();
Note that there is no explicit Content-Type: application/json header. That is not an omission. In the Laravel source I checked, the pending request starts out in JSON mode, so an array passed to post() is sent as JSON. The tool's FAQ says the same.
A file upload with extra fields, from curl -F file=@report.pdf -F title=Q3 -H "Authorization: Bearer $TOKEN" ..., becomes:
<?php
use Illuminate\Support\Facades\Http;
$response = Http::withToken(config('services.shop.token'))
->attach('file', file_get_contents('report.pdf'), 'report.pdf')
->timeout(30)
->post('https://api.example.com/v1/reports', [
'title' => 'Q3',
]);
attach() switches the request to multipart, and the extra array passed to post() is sent as additional multipart fields. I confirmed that in the framework's multipart handling; I did not send the request anywhere.
Three behaviors to check in any conversion
1. Body format: JSON or form
curl's -d without a Content-Type header sends application/x-www-form-urlencoded, even when the data looks like JSON. Laravel defaults to JSON. The page says the converter sends JSON when the body is clearly JSON and tells you so, uses asForm() for form posts, and withBody() for other bodies. In Laravel, asForm() sets form-encoded parameters and the matching content type, while withBody() takes a raw string and a content type that defaults to application/json. If an API is picky about the format, confirm which one the original curl command was really sending.
2. Redirects
Plain curl does not follow redirects unless you pass -L. The Laravel HTTP client, built on Guzzle, follows them by default. In the Laravel source, redirects are only altered by maxRedirects() and withoutRedirecting(); there is no default override. If your curl command had no -L and you want identical behavior, add ->withoutRedirecting():
<?php
use Illuminate\Support\Facades\Http;
$response = Http::withoutRedirecting()
->throw()
->get('https://api.example.com/v1/orders/42');
3. Error handling
Laravel does not throw on 4xx or 5xx responses by default; you get a response object and check $response->failed() or similar. ->throw() changes that, and the converter's toggle adds it. In the source, throw() only registers a callback that is applied after the response arrives, so connection failures are a separate concern and surface as a ConnectionException.
Before you ship the generated code
-
Move secrets out. Replace any literal token with
config('services.x.token')backed by an environment variable. Generated code with a real key in it is a leak waiting for a commit. -
Drop browser noise. A "Copy as cURL" from DevTools includes cookies, user-agent and
sec-*headers. Server-to-server calls rarely need them, and cookies in particular can hold session data you should not paste into a code file. -
Set a timeout. If the curl command had
--max-timeor--connect-timeout, check that the output carries a timeout. If it did not have one, add->timeout()yourself. - Add retries deliberately, not by default. Retrying a non-idempotent POST can create duplicates.
Test the call without hitting the API
The page's FAQ points at Http::fake() and Http::assertSent(). Both exist on the HTTP client factory. A Pest test for the order example might look like this:
<?php
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Request;
it('creates an order', function () {
Http::fake(['api.example.com/*' => Http::response(['id' => 1])]);
// ... run the code under test ...
Http::assertSent(function (Request $request) {
return $request->url() === 'https://api.example.com/v1/orders'
&& $request['sku'] === 'A-100';
});
});
I checked the snippet for syntax only; it needs your app's test setup to run. Faking the call and asserting on the URL and body is the quickest way to prove the conversion produced the request you meant.
When to convert by hand instead
Use the converter for the first draft, not as a guarantee. Review the output manually when the curl command uses client certificates, a proxy, custom TLS settings, cookies from a cookie jar, or streaming. The tool page does not claim to cover those, and Laravel has separate methods for several of them, such as withoutVerifying(), which you should never leave in production code.
Frequently asked questions
How do I convert a curl command to Laravel code?
Paste the command into the converter, choose the response style and error handling, and copy the generated Http:: code. Then check the body format, redirects and secrets.
Why does the generated code have no Content-Type header?
Laravel sends arrays as JSON by default, so the header is added for you. It is only set explicitly when the body is form data or a raw string.
Why does my Laravel request behave differently from curl?
The usual causes are redirects (curl does not follow them without -L, Laravel does) and the body format (curl's -d sends form data unless you set a content type).
Is it safe to paste an API token into the converter?
The page says conversion happens in your browser and tokens are not uploaded. Even so, treat any real token you paste as exposed and rotate it, or paste the command with a placeholder.
Can I convert a Chrome "Copy as cURL" command?
Yes, the page says it accepts that output. Leave the browser-headers option off unless the target API needs those headers.
update log
- 23 November 2026: first version.
- To recheck on each update: the tool's options and supported flags, its sample output (replace my hand-written examples with real output once captured), and Laravel's HTTP client defaults.
Originally published on DEV Talk.
Top comments (0)