curl to Kotlin, Swift, Dart, Go and JavaScript converter

Paste a curl command (with quotes, backslash line breaks, $'...' strings, -H, -d, -F, -u, -G) and get working code for Kotlin OkHttp, Swift URLSession, Dart http or dio, Go, Python requests, fetch or axios. The mobile outputs follow each platform's idioms, and -k is flagged as insecure.

Updated

Paste what Chrome, Firefox, Safari or Postman give you (bash format). Quotes, line continuations and $'...' strings are understood. Nothing is sent anywhere.

curl only follows redirects with -L; the libraries follow them by default. Tick this to copy curl's behaviour.

Off by default: the code keeps certificate checks on and the page warns. Turn it on only for a test server you control.

Kotlin OkHttp

POST api.example.com/v1/orders

3 headers, body: JSON

Kotlin OkHttp

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody

// Call from a coroutine. OkHttp's execute() blocks, so it runs on Dispatchers.IO.
suspend fun sendRequest(): String = withContext(Dispatchers.IO) {
    val client = OkHttpClient()

    val body = """{"sku": "TSHIRT-M", "qty": 2, "gift": true, "note": null}""".toRequestBody("application/json".toMediaType())

    val url = "https://api.example.com/v1/orders".toHttpUrl().newBuilder()
        .addQueryParameter("source", "app")
        .build()

    val request = Request.Builder()
        .url(url)
        .header("Authorization", "Bearer YOUR_TOKEN")
        .header("Accept", "application/json")
        .post(body)
        .build()

    client.newCall(request).execute().use { response ->
        check(response.isSuccessful) { "HTTP ${response.code}: ${response.body?.string()}" }
        response.body?.string().orEmpty()
    }
}
Method
POST
URL
https://api.example.com/v1/orders?source=app
Headers
Authorization, Content-Type, Accept
Body
JSON
  • Setup: Gradle: implementation("com.squareup.okhttp3:okhttp:5.5.1") (the latest release listed on its GitHub page on 2026-11-11). The coroutine version also needs kotlinx-coroutines-core (or -android).
  • The JSON body is sent as a string with its Content-Type, in the same bytes curl sent.
  • --compressed asks the server for compressed responses and decodes them. These clients negotiate gzip by themselves when you leave Accept-Encoding to them, so no extra code is generated.

How is a curl command turned into code?

The command is first split into words the way a shell would. Single quotes keep everything literal, double quotes allow \" \\ \$ escapes, $'...' strings decode \n, \t, \xNN and \uNNNN, a backslash at the end of a line joins the next line, and adjacent pieces such as -H'A: b' become one word. Then the options are read: -X, -H, -d, --data-raw, --data-binary, --data-urlencode, --json, -F, -u, -G, -I, -A, -e, -b, -m, -L, -k and --compressed, including clusters like -sSL and attached values like -XPOST. Options that don't change the request (-s, -v, -i) are ignored.

From those options one request is built. The method follows curl's rule: -X wins, -I means HEAD, -d or -F means POST, otherwise GET. A body with no Content-Type is sent by curl as application/x-www-form-urlencoded, so that header is added to the code; JSON bodies are written as real objects where the language has a natural form, and as exact text otherwise. -G moves the data into the query string. A $VARIABLE or $(command) in the text is flagged, because curl's shell would have expanded it.

The Dart, Kotlin and Swift writers use what each platform's developers expect: Uri.https with queryParameters and MultipartRequest for the Dart http package, FormData and MultipartFile for dio, Request.Builder with Credentials.basic and a suspend function on Dispatchers.IO for OkHttp, and URLComponents with async/await (or a completion handler for older iOS) for URLSession. -k is flagged as insecure and only generates the verification-skipping code if you ask for it.

-X given            -> that method
-I                  -> HEAD
-d / --json / -F    -> POST
nothing             -> GET
-G + -d             -> GET with ?query

Which curl option becomes what in each language?

How each library expresses the same curl option
curlKotlin OkHttpSwift URLSessionDart http / dioPython requests
-H 'A: b'.header("A", "b")request.setValue("b", forHTTPHeaderField: "A")headers: {'A': 'b'}headers={"A": "b"}
-d 'a=1&b=2'FormBody.Builder().add(...)request.httpBody = Data(...)body: {'a': '1'} / data: {...}data={"a": "1"}
--json / JSON -dtoRequestBody("application/json".toMediaType())httpBody + Content-TypejsonEncode(...) / data: {...}json={...}
-F file=@a.pngMultipartBody.Builder().addFormDataPart(...)boundary-built DataMultipartRequest / FormDatafiles={...}
-u user:passCredentials.basic(user, pass)Authorization: Basic + base64Authorization: Basic + base64Encodeauth=(user, pass)
-G -d q=1HttpUrl.Builder().addQueryParameterURLComponents.queryItemsUri.https(..., {query}) / queryParametersparams={...}
-m 30callTimeout(30, SECONDS)request.timeoutInterval = 30.timeout(Duration) / BaseOptionstimeout=30
-kcustom X509TrustManagerURLSessionDelegate with serverTrustbadCertificateCallbackverify=False

How to convert a curl command to code

  1. 1
    Copy the commandIn Chrome DevTools, right-click a request in the Network tab and choose Copy as cURL (bash). Postman has Code, then cURL. Paste it as it is, including the backslashes at line ends.
  2. 2
    Pick the languageKotlin, Swift and Dart each have style options: a suspend function or a blocking call, async/await or a completion handler, http or dio.
  3. 3
    Read the notesVariables like $TOKEN, files read with @, ignored options, a missing scheme and -k are all listed. Replace placeholders with real values.
  4. 4
    Copy, add the dependency and runThe setup line says what to install. Replace any secret with an environment variable or your app's secure storage before you commit.

Frequently asked questions

Why did the code get a Content-Type I did not write?
curl sends the data from -d as application/x-www-form-urlencoded when no Content-Type is given, so the code does the same to match what the server received. If your data is JSON, add -H 'Content-Type: application/json' to the curl command. Without it, curl itself was sending the wrong type.
What does -k do, and why isn't it copied by default?
-k (--insecure) makes curl skip TLS certificate verification, which curl's manual says makes the transfer insecure. A copied bypass tends to stay in the code, so this page keeps verification on and warns. Tick the option to emit the bypass for a test server you control.
Does Kotlin OkHttp need a background thread?
Yes. execute() blocks until the response arrives, and on Android a call on the main thread throws NetworkOnMainThreadException. The default output is a suspend function using withContext(Dispatchers.IO). For a plain JVM tool choose the blocking style.
How do I send multipart form data with Swift's URLSession?
URLSession has no multipart helper, so the body is built by hand: a boundary, one part per field with Content-Disposition (and Content-Type for files), a closing boundary, and a Content-Type header that names the boundary. The generated addPart function does this for you.
Why do the examples set no Accept-Encoding for --compressed?
The clients negotiate and decode gzip themselves when you leave the header alone. Setting Accept-Encoding yourself can switch that off (Go and OkHttp then leave decoding to you), so the header from a browser copy is dropped on purpose.
My command has $TOKEN or $(date). What happens?
curl's shell expands those before curl runs. The page can't, so it keeps the text as written and names each variable in the notes. Replace it with the value, or read an environment variable in your code.
Which curl commands won't convert?
Anything that isn't HTTP or HTTPS (ftp, scp), Windows cmd.exe quoting with ^ characters, digest or NTLM authentication, client certificates, proxies, and uploads with -T. The page says so in the notes instead of guessing, and reads only the first command before a pipe or &&.

Sources

Related tools

See all 135 free tools

Need a custom dev tool for your team?

We build internal tools, dashboards, APIs, and SaaS platforms. If you can describe it, we can ship it.

Built by CountryDevs · No signup · No ads · We count visits, never what you enter