curl to Dart
Convert curl commands to Dart http package code. Supports Flutter and Dart projects with headers, POST data, and auth.
Presets:
Paste your raw curl request command here. Safe local storage is used.
Dart code updated. Method: POST, URL host: api.example.com.
Target Host
api.example.com
HTTP Method
POST
Headers Detected
2
Cookies / Auth
No / No
Dart Line Count
14
How curl to Dart conversion works
Dart's http package is the standard HTTP client for Flutter and Dart. Curl flags map to named parameters:-H becomes theheaders map, and-d becomes thebody argument. The output uses async/await with Dart futures.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Converting an API's curl example into Dart for a Flutter app.
- Reproducing a captured request inside an existing Dart client.
- Getting the header map and body encoding right for a POST.
- Producing a snippet to drop into a repository class.
- Checking which curl flags the http package cannot express.
Frequently Asked Questions
- Which client should I use in Flutter?
- The package:http Client is the portable choice and works on web, where dart:io is unavailable. dart:io's HttpClient is lower level and native-only — using it breaks a Flutter web build.
- Do I need to close the client?
- Yes, if you create one: call client.close() when finished, otherwise the underlying connections stay open. The top-level helpers (http.get, http.post) create and close a client per call, which is convenient but gives up connection reuse.
- How do I send and decode JSON?
- Encode with jsonEncode(map) into body and set the Content-Type header; decode with jsonDecode(response.body). package:http does not do either automatically, and response.body is always a String.
- Why do Android release builds fail with a network error?
- Android requires the INTERNET permission in AndroidManifest.xml — debug builds add it implicitly, release builds do not. Cleartext HTTP is also blocked by default from Android 9 onwards.
- How do I set a timeout?
- There is no timeout parameter — chain .timeout(Duration(seconds: 10)) on the returned Future, which throws TimeoutException. dart:io's HttpClient does expose connectionTimeout directly.
- Should JSON decoding run on the main isolate?
- Not for large payloads — `jsonDecode` is synchronous and blocks the UI thread, dropping frames. `compute()` moves it to a background isolate, which is the standard Flutter fix for a list that stutters while loading.
- How is certificate pinning done?
- Through `HttpClient.badCertificateCallback`, or a `SecurityContext` with your own trusted certificate. The callback receives the certificate and returns whether to accept it — returning `true` unconditionally disables validation entirely.
Common errors and gotchas
- Forgetting `jsonEncode` on a Map body, which otherwise sends Dart's toString output.
- Omitting the content-type, which the http package does not infer from the body.
- Assuming cookies persist, when the http package has no jar — that needs a client wrapper.
- Not closing the client, which on a long-lived app leaks sockets.
- Expecting a non-2xx to throw, when you must check `statusCode` yourself.
Related Developer Utilities tools
RegExp Tester
Test regular expressions and inspect matches locally.
Regex Visualizer
Visual regex pattern diagram with live match highlighting and capture group annotations.
Subnet Calculator
Compute CIDR subnets, usable hosts, and network ranges.
Cron Parser
Translate cron syntax into plain English.
URL Parser
Break a URL into protocol, host, path, and query parts.
HTML Previewer
Paste HTML and see it rendered live in a safe, sandboxed preview.
HTTP Status Code Reference
Search and look up every HTTP status code and its meaning.
MIME Type Lookup
Find the MIME type for a file extension, or the extensions for a MIME type.