cURL to Dart
Paste a curl command and get Dart code that makes the same request with package:http.
cURL to Dart parses your command in the browser. Credentials in the command never leave your device.
Convert to Swift instead
About cURL to Dart
Backend documentation gives you a curl command; a Flutter app needs Dart. This converter bridges the two, parsing the curl flags the way curl itself does and emitting code that uses package:http — the package almost every Dart and Flutter project already depends on. Headers are collected into a typed map, a JSON body becomes a Dart map encoded with jsonEncode rather than a pasted string, and basic auth is rebuilt with base64Encode from the decoded credentials. Verbs that the shorthand helpers do not cover fall back to an http.Request, so an unusual method still produces working code instead of a silent gap.
Features
- Parses -X, -H, -d, --data-raw, --json, -u, -b, -A, -e and -G the way curl does
- Emits code that uses package:http, the standard Dart HTTP client
- Headers collected into a typed Map<String, String>
- JSON bodies rendered as a Dart map and encoded with jsonEncode
- Basic auth rebuilt with base64Encode rather than a pasted Base64 string
- Falls back to http.Request for verbs without a shorthand helper
- Warns about curl flags with no meaningful Dart equivalent
How to use the cURL to Dart
- Paste the curl command from your API documentation
- Read the generated Dart on the right
- Check any warnings about flags that could not be carried over
- Copy the code, or download it as a .dart file
Example
Input
curl -X PUT https://api.example.com/users/1 -H 'Authorization: Bearer TOKEN' -d '{"role":"admin"}'
Output
final response = await http.put(url, headers: headers, body: body);
The verb comes from -X, and the JSON body is built as a Dart map before encoding.
Common errors & troubleshooting
- The package cannot be found when the file runs. — Add it to pubspec.yaml under dependencies as http, then run dart pub get. It is not part of the SDK, though it is maintained by the Dart team.
- The request fails only on Flutter web. — That is CORS, not the code. A browser applies the same-origin policy that a curl command never sees, so the API has to send the right Access-Control headers.
- A string in the body is being interpolated oddly. — Dollar signs start interpolation in Dart. They are escaped in the generated literals, but if you paste a value in by hand, escape any $ as \$.
- The request works on Android but not on a local server in the simulator. — An Android emulator cannot see localhost on the host machine; use 10.0.2.2 instead. Cleartext HTTP also needs to be permitted in the Android network security config.
Frequently asked questions
- Does the generated code work in a Flutter app?
- Yes. package:http works the same in Flutter and in plain Dart, so the request code can be pasted into a service class as-is. Only the printing at the end is worth replacing with whatever your app does with the response.
- Should I use package:http or Dio?
- package:http is the smaller, official option and covers most requests. Dio adds interceptors, cancellation and multipart conveniences, and its API is close enough that translating this output is straightforward.
- How is a JSON body converted?
- It is parsed and written out as a Dart map literal, then encoded with jsonEncode. That keeps nested objects and arrays readable, and lets you replace values with variables directly.
- What if the method has no http.get style helper?
- The generated code builds an http.Request with the verb as a string and sends it through send(), which handles PURGE, LINK or anything else an API might use.
- Is the curl command uploaded to convert it?
- No. Parsing and code generation happen in your browser, so bearer tokens and API keys inside the command stay on your device.
Related tools
- cURL to Swift — Turn a curl command into Swift code that uses URLSession.
- cURL to Fetch — Convert a curl command to a JavaScript fetch() call.
- cURL to Python — Convert a curl command to Python requests code.
- cURL to Go — Convert a curl command to Go net/http code.
- cURL to Node.js (axios) — Convert a curl command to Node.js axios code.
- API Request Client — Send HTTP requests, build headers and params, inspect responses — your last 25 requests are saved locally.
All ArrayKit tools