Skip to content
100% Client-SideZero UploadJava OkHttp Output

cURL to Java OkHttp Converter — Offline & Secure

Paste a cURL command and get a ready-to-run OkHttp class: a Request.Builder chain with method and headers, RequestBody.create for the payload, and try-with-resources response handling — converted completely offline in your browser.

  • Zero upload, ever

    Parsing and code generation run in your browser — URLs, headers, and tokens never touch a server.

  • Live 100 ms conversion

    Output updates as you type or paste, with one-keystroke copy via Cmd/Ctrl + Enter.

  • Builder-chain output

    The fluent Request.Builder style every OkHttp codebase already uses.

Paste a cURL command to convert

Examples
100% Client-Side: Tokens & credentials never leave your browser.

cURL command

Paste a cURL command — idiomatic code appears here instantly, converted entirely in your browser.

Technical documentation

How cURL maps to OkHttp

OkHttp builds requests with a fluent chain, and the generated code follows it literally: .url(...) from your endpoint, .get()/.post(body)/.put(body) from the method (or .method("VERB", body) for exotic verbs), one .header(name, value) per -H flag, and .build(). The result reads top-to-bottom like the cURL command it came from.

The snippet is wrapped in a Main class with try-with-resources on the Response — the pattern OkHttp's own documentation recommends — and prints the body via response.body().string().

Payloads, media types, and wire fidelity

Bodies are passed to RequestBody.create. JSON payloads are compacted to a single-line string literal — escaped to Java's rules — so the chain stays readable even for large documents. The MediaType.parse(...) declaration is emitted only when your command carries a Content-Type, keeping GET requests free of dead variables.

Form data and raw text keep their exact bytes; query strings are preserved verbatim in the URL; repeated -d flags join with & the way curl joins them; and --data-urlencode values are percent-encoded during conversion.

Authentication and headers

Basic auth from -u — or credentials embedded in the URL — is base64-encoded at conversion time and attached as an Authorization: Basic header line in the chain, so the snippet carries no runtime encoding calls. Explicit Authorization headers (bearer tokens, API keys) pass through untouched and suppress the precomputed header to avoid duplicates.

Because every header is a separate .header(...) call, adding signing headers, trace IDs, or tenant tags later is a one-line change in the same style.

Running the generated Java

Add OkHttp to your build — Maven: com.squareup.okhttp3:okhttp:4.12.0, or Gradle: implementation 'com.squareup.okhttp3:okhttp:4.12.0' — then drop the class into any project and run main. Java 8+ is sufficient.

For Android or server code, move the OkHttpClient instance to a shared field or DI provider (a client should be reused), and extend with interceptors for auth refresh or logging — the request chain transfers unchanged.

Frequently asked questions

Does the converter work offline?

Yes. The page loads once as static HTML and JavaScript; the transpilation itself needs no network, so commands with production credentials never leave your machine.

What do I need to run the generated Java code?

Java 8+ and the OkHttp dependency — com.squareup.okhttp3:okhttp:4.12.0 via Maven or Gradle. The snippet is otherwise self-contained with a runnable main method.

How is basic auth (-u) converted for Java?

Credentials are base64-encoded during conversion and emitted as .header("Authorization", "Basic ...") in the builder chain — byte-identical to what curl sends, with no runtime encoding logic.

Why is the JSON body on one line in the output?

OkHttp takes the body as a string, and compacting valid JSON keeps the builder chain readable and the literal copy-paste safe. Pretty-print the payload after it arrives if you need it formatted.

Does the output support custom HTTP methods?

Yes. Standard verbs map to .get(), .post(), .put(), .patch(), .delete(), and .head(); anything else is emitted as .method("VERB", body), which OkHttp sends verbatim.

Can I reuse the OkHttpClient across requests?

You should — OkHttp performs best when its client is shared. Move the OkHttpClient declaration to a field or DI provider; the request-building chain needs no changes.