Convert curl to Dart
Convert curl commands to Dart code using the http package. curl2code runs entirely in your browser via WebAssembly — your data stays private. For Kotlin, try our curl to Kotlin converter. For Swift, see curl to Swift. Below are ready-to-use Dart examples for Flutter.
How to copy curl from your browser
- 1
Open DevTools
Press F12 or Ctrl+Shift+I to open your browser developer tools.
- 2
Go to the Network tab
Click the Network tab and perform the action that triggers the HTTP request.
- 3
Copy as cURL
Right-click the request → Copy → Copy as cURL. Then paste it above.
Frequently Asked Questions
What is the Dart http package?
The http package is the recommended HTTP client for Dart and Flutter. It provides a simple, Future-based API for GET, POST, multipart uploads, and streaming. Install with dart pub add http. It works across all Dart platforms — mobile, web, and server. curl2code uses it as the default for Dart conversions.
http vs dio vs HttpClient — which should I use?
http is simple and lightweight — great for basic requests. dio adds interceptors, FormData, download progress, and cancellation. HttpClient (dart:io) is lower-level and built-in but more verbose. For Flutter apps needing interceptors, choose dio. For similar mobile clients, see curl to Kotlin or curl to Swift.
How to handle authentication in Dart?
Pass headers to the request: http.get(url, headers: { "Authorization": "Bearer $token" }). For Basic auth, encode with base64Encode(utf8.encode("$user:$pass")). curl2code converts -u and -H 'Authorization' flags to Dart code with properly typed headers.
How to send multipart form data in Dart?
Use http.MultipartRequest: create the request, add fields with request.fields['key'] = 'value', and files with request.files.add(await http.MultipartFile.fromPath('file', path)). Then send with request.send(). curl2code converts -F flags to this pattern.
How to handle HTTP errors in Dart?
The http package doesn't throw on HTTP errors — check response.statusCode manually. Wrap calls in try/catch for SocketException (network errors) and TimeoutException. Use http.Client with close() for proper resource cleanup in long-lived applications.
How to use async/await with Dart HTTP?
All Dart HTTP methods return Future — use final response = await http.get(Uri.parse(url)). Dart's async/await is built into the language. For parallel requests, use Future.wait([request1, request2]). For similar async patterns, see curl to TypeScript or curl to Swift.
How to set timeouts in Dart?
Use the .timeout() method on any Future: http.get(url).timeout(Duration(seconds: 30)). This throws TimeoutException when exceeded. For more control, create an http.Client and configure via the underlying HttpClient from dart:io with connectionTimeout.
How to use a proxy in Dart?
Use HttpClient from dart:io: HttpClient()..findProxy = (uri) => 'PROXY proxy:8080'. For the http package, create a custom IOClient wrapping the configured HttpClient. Dart also respects HTTP_PROXY and NO_PROXY environment variables.
How to send a POST request with JSON body in Dart?
Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to Dart using curl2code. The generated code uses http.post(uri, body: jsonEncode(data), headers: {'Content-Type': 'application/json'}). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the http code.
How to add Bearer token authorization in Dart?
Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates http code with the auth header: headers: {'Authorization': 'Bearer YOUR_TOKEN'}. curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.
How to set Content-Type header in Dart?
curl2code converts curl -H "Content-Type: application/json" URL to http code with the proper header: headers: {'Content-Type': 'application/json'}. For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct http API.