Skip to content

Convert cURL commands to Dart

A cURL command is a compact record of an HTTP request: the URL, method, headers and body.

OUTPUT FORMATSHTMLJSONMarkdown

This page turns that record into Dart code you can drop into a project that depends on package:http. Paste the command into the input box, read the generated snippet, and copy it with the button. The guide below explains the two fields, how to get a cURL string out of a browser, and how to tell a conversion problem apart from a runtime HTTP error.

What the converter does

The tool takes one cURL command as text and produces a Dart snippet. The generated code targets the http package, so the project needs that dependency before the snippet will compile. The output is a starting point: review the URL, method, headers and body against the request you actually want to send, then adapt naming and error handling to your codebase.

The two visible controls are simple:

  • The input textarea (id curl-command) holds the cURL command. Its placeholder shows a minimal example, curl example.com.
  • The copy button (id clipboard) copies the generated Dart code to your clipboard.

A short checklist before you trust the output:

  1. Confirm the method matches the original request (GET, POST and so on).
  2. Confirm every header you need survived, especially content type and authorization headers.
  3. Confirm the body is present for methods that send one.
  4. Confirm the URL is the one you meant, including any query string.
  5. Run the snippet in a small test file before wiring it into a larger app.

Reading the generated Dart

The sample output on the page is a minimal GET request. It imports package:http under the alias http, parses a URL into a Uri, awaits http.get, throws if the status code is not 200, and prints the response body. That shape is a useful template: the import and the Uri.parse call stay the same, while the method call and the response handling change with your request.

One detail worth noticing is the failure distinction. A conversion problem shows up before you run anything: the snippet will not compile, or it points at the wrong URL or method. A runtime HTTP error is different: the code compiles and runs, but the server answers with a status other than 200, and the sample throws an exception with the status code in the message. Treat those as two separate debugging paths.

For requests that send data, expect the generated code to differ from the sample: the method call and the body handling will reflect what the cURL command contained. Always compare the generated snippet against the original command line by line.

Getting a cURL command from your browser

Browser developer tools can copy any request as a cURL command. Open the network panel, reproduce the request you care about, right-click the entry and choose the copy-as-cURL option. The exact menu wording varies by browser, so the linked walkthroughs for Chrome, Safari and Firefox are the quickest reference.

Once you have the string, paste it into the input box on this page. If the request includes cookies or authorization headers, decide whether those belong in the Dart code you keep; copying them into a shared repository is usually a mistake.

Other target languages

If Dart is not the destination, the same input can be converted for other languages and clients, including CFML, Elixir, Go, Java, JavaScript Fetch, JSON, MATLAB, NodeJS with Axios, NodeJS with fetch, NodeJS with Request, PHP, Python, R and Rust. Each converter follows the same pattern: paste the command, read the output, copy it.

Frequently asked questions

Which Dart package does the generated code use?

The sample imports package:http as http, so add that dependency to your project before running the snippet.

Why does the sample throw an exception?

It checks the response status and throws when the code is not 200, including the status code in the message. That is a deliberate guard, not a conversion failure.

Will headers and request bodies be carried over?

The converter works from the full cURL command, so headers and bodies present in the command are reflected in the output. Check the generated snippet against the original command before relying on it.