cURL converter · Kotlin

cURL to Kotlin

Paste a curl command and get idiomatic Kotlin. We use the Companion extension helpers (toRequestBody, toMediaTypeOrNull) instead of legacy Java overloads, and translate -F, -u, --max-time, and -x into their OkHttp equivalents.

InputcURL command
1 secret
MethodPOST·Headers2·Body46 B· Chars 187
OutputJVM · OkHttp / Kotlin(idiomatic)
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody

val client = OkHttpClient.Builder().followRedirects(false).followSslRedirects(false).build()
val body = "{\"to\":\"+15551234567\",\"body\":\"Hello from curl\"}".toRequestBody("application/json".toMediaTypeOrNull())
val request = Request.Builder()
  .url("https://api.example.com/v1/messages")
  .method("POST", body)
  .header("Authorization", "Bearer sk_test_123")
  .header("Content-Type", "application/json")
  .build()

client.newCall(request).execute().use { response ->
  println(response.body?.string())
}
Inspect

Top guides for Kotlin

All guides →

Common questions

Why the extension-function style?
The Companion helpers (toRequestBody, toMediaTypeOrNull, asRequestBody) are the current OkHttp Kotlin API. The old MediaType.parse(...) and RequestBody.create(MediaType, String) overloads are deprecated.
Does it work with Ktor instead?
Not today — we emit OkHttp because it's the safe default across Android and JVM. Ktor client output is on the shortlist.
What about coroutines?
The default output uses execute() so it drops into any function. Wrap it in withContext(Dispatchers.IO) for structured concurrency, or await an OkHttp interceptor's Deferred for a fully suspending call.
Is my curl sent anywhere?
No. Parsing and code generation happen entirely in your browser.

Also convert cURL to

All guides →

Same parser, same idiomatic output — swap the target language whenever your stack changes. Every hub carries its own reference guides for methods, payloads, and auth.