Skip to content
koducathome

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.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Kotlin OkHttp code appears instantly.
  3. Set up: Add com.squareup.okhttp3:okhttp (version 4 or later) to your Gradle dependencies.
  4. Run it: Run main from your IDE or Gradle. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no OkHttp equivalent.

Example

GET with headers → Kotlin OkHttp

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Kotlin OkHttp
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.