cURL to Dart / Dio Converter

Paste a cURL command, for example from your browser’s developer tools (Copy as cURL) or from API documentation, and get a ready-to-use Dart function for Dio or the http package. Headers, query parameters, JSON bodies, form fields and file uploads are converted, and options that do not affect the request are listed so nothing is silently lost. Commands often contain API keys, so everything stays on your device.

Runs in your browser · Your tokens never leave your device

Loading the tool…

Tip: in browser developer tools, use Copy as cURL (bash) for the most accurate result.

How to use the cURL to Dart / Dio Converter

  1. Copy the request as cURL. In Chrome or Edge: Developer tools › Network › right-click a request › Copy › Copy as cURL (bash).
  2. Paste it here. Commands split over several lines with \, ^ or ` are supported.
  3. Choose Dio or the http package and, if you like, a function name.
  4. Copy the code into your project and add the package to pubspec.yaml.

What is converted

Method
From -X. Without -X the method is POST when there is a body or form, HEAD with -I, and GET otherwise, as curl does.
URL and query parameters
Query parameters are taken out of the URL into a map, decoded, so they are easy to change. With -G, -d data is added to the query instead of the body.
Headers
-H, -A (User-Agent), -e (Referer), -b (Cookie) and -u (turned into a Basic Authorization header). For Dio, Content-Type moves to Options.contentType.
Body
A JSON body becomes a Dart map or list literal. key=value&… data becomes a form map. Anything else is sent as text. -F fields become FormData (Dio) or a MultipartRequest (http); -F file=@path becomes a file upload.

Examples

These outputs were produced by the same code that runs in the tool above.

POST JSON with a bearer token

A typical API call with headers, a query parameter and a JSON body, converted for Dio.

cURL command

curl -X POST 'https://api.example.com/v1/orders?notify=true' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"customer_id": 1024, "items": [{"sku": "ZV-1001", "qty": 2}], "gift": false}'

Dart code

import 'package:dio/dio.dart';

Future<Response<dynamic>> sendRequest() async {
  final Dio dio = Dio();
  final Response<dynamic> response = await dio.request<dynamic>(
    'https://api.example.com/v1/orders',
    queryParameters: <String, dynamic>{
      'notify': 'true',
    },
    data: <String, dynamic>{
      'customer_id': 1024,
      'items': <dynamic>[
        <String, dynamic>{
          'sku': 'ZV-1001',
          'qty': 2,
        },
      ],
      'gift': false,
    },
    options: Options(
      method: 'POST',
      headers: <String, dynamic>{
        'Authorization': 'Bearer YOUR_TOKEN',
      },
      contentType: 'application/json',
    ),
  );
  return response;
}
  • Add Dio to pubspec.yaml: dio: ^5.0.0

Form login with the http package

A URL-encoded form body, converted for package:http.

cURL command

curl https://auth.example.com/token -d "grant_type=password" -d "username=amina%40example.com" -d "password=SECRET"

Dart code

import 'package:http/http.dart' as http;

Future<http.Response> sendRequest() async {
  final Uri uri = Uri.parse('https://auth.example.com/token');
  final http.Request request = http.Request('POST', uri);
  request.bodyFields = <String, String>{
    'grant_type': 'password',
    'username': 'amina@example.com',
    'password': 'SECRET',
  };
  final http.StreamedResponse streamed = await request.send();
  return http.Response.fromStream(streamed);
}
  • Add http to pubspec.yaml: http: ^1.0.0

Frequently asked questions

Are my tokens or passwords uploaded?

No. The command is parsed on your device. Still, avoid committing real tokens to source control; load them from configuration or secure storage.

Which curl options are ignored?

Options that only change how curl itself behaves, such as -L, -k, -s, -v, --compressed, -o and timeouts, are listed under the result. Configure the matching behaviour in Dio (for example followRedirects) if you need it.

Does it work with Windows (cmd) commands?

Yes. Chrome’s Copy as cURL (cmd) uses ^ for line breaks, which is supported. Double quotes with ^" escapes from cmd may need cleaning up; the bash version is the most reliable.

Does the code run on Flutter web?

Yes, both Dio and http work on the web, but the browser enforces CORS, and some headers such as Cookie or User-Agent cannot be set from browser code.

Limitations and edge cases

  • Shell variables like $TOKEN are kept as text, not expanded.
  • Bodies read from files (-d @file) are left as a placeholder to fill in.
  • Client certificates, proxies and other transport options are not converted.

Read the privacy policy for how the site handles data.