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 →POST in Kotlin
/how-to/curl-post-in-kotlin
GET in Kotlin
/how-to/curl-get-in-kotlin
JSON in Kotlin
/how-to/send-json-with-curl-in-kotlin
multipart form-data in Kotlin
/how-to/send-multipart-with-curl-in-kotlin
Bearer token in Kotlin
/how-to/curl-bearer-auth-in-kotlin
Basic auth in Kotlin
/how-to/curl-basic-auth-in-kotlin
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.