cURL to Kotlin Converter
Convert curl commands to Kotlin code using OkHttp. Paste a command and the Kotlin snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The Kotlin OkHttp code appears instantly.
- Set up: Add
com.squareup.okhttp3:okhttp(version 4 or later) to your Gradle dependencies. - Run it: Run
mainfrom your IDE or Gradle. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no OkHttp equivalent.
Example
GET with headers → Kotlin OkHttp
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'import okhttp3.OkHttpClient
import okhttp3.Request
fun main() {
val client = OkHttpClient()
val request = Request.Builder()
.url("https://api.example.com/v1/users?page=2")
.header("Accept", "application/json")
.header("Authorization", "Bearer YOUR_TOKEN")
.get()
.build()
client.newCall(request).execute().use { response ->
println(response.code)
println(response.body?.string())
}
}Common use cases
- Android apps
- Kotlin backend services
- Command-line tools
Converting curl to Kotlin OkHttp
OkHttp is the most common HTTP client for Kotlin on the JVM and Android; the code uses OkHttp 4's Kotlin extensions.
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent OkHttp code. Options that have no OkHttp equivalent are listed under the editors rather than silently dropped.
Limitations
- The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Can I use this in an Android app?
Yes — but make the call off the main thread, for example in a coroutine with Dispatchers.IO or with enqueue.
Why .use { }?
It closes the response body when done, which OkHttp requires to free the connection.
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.