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
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?
| curl | Kotlin OkHttp | Swift URLSession | Dart http / dio | Python 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 -d | toRequestBody("application/json".toMediaType()) | httpBody + Content-Type | jsonEncode(...) / data: {...} | json={...} |
| -F file=@a.png | MultipartBody.Builder().addFormDataPart(...) | boundary-built Data | MultipartRequest / FormData | files={...} |
| -u user:pass | Credentials.basic(user, pass) | Authorization: Basic + base64 | Authorization: Basic + base64Encode | auth=(user, pass) |
| -G -d q=1 | HttpUrl.Builder().addQueryParameter | URLComponents.queryItems | Uri.https(..., {query}) / queryParameters | params={...} |
| -m 30 | callTimeout(30, SECONDS) | request.timeoutInterval = 30 | .timeout(Duration) / BaseOptions | timeout=30 |
| -k | custom X509TrustManager | URLSessionDelegate with serverTrust | badCertificateCallback | verify=False |
How to convert a curl command to code
- 1Copy 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.
- 2Pick 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.
- 3Read the notesVariables like $TOKEN, files read with @, ignored options, a missing scheme and -k are all listed. Replace placeholders with real values.
- 4Copy, 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?
What does -k do, and why isn't it copied by default?
Does Kotlin OkHttp need a background thread?
How do I send multipart form data with Swift's URLSession?
Why do the examples set no Accept-Encoding for --compressed?
My command has $TOKEN or $(date). What happens?
Which curl commands won't convert?
Sources
- curl manual: -d/--data, --data-raw, --data-binary, -G, -F, --compressed (options and defaults) (checked 11 Nov 2026)
- curl manual: --json, -k/--insecure, -L/--location, -m/--max-time, -u/--user, -X/--request, -A/--user-agent (checked 11 Nov 2026)
- pub.dev: http package (^1.6.0; Uri.https, post with body Map) (checked 11 Nov 2026)
- pub.dev: dio package (^5.11.1; FormData, MultipartFile.fromFile, queryParameters, Options) (checked 11 Nov 2026)
- OkHttp on GitHub: release 5.5.1 and the Gradle coordinate (checked 11 Nov 2026)
- Apple: URLSession (async data(for:) and the completion-handler dataTask) (checked 11 Nov 2026)
- Go net/http: Client.CheckRedirect and ErrUseLastResponse (checked 11 Nov 2026)
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