Convert curl to Clojure
curl2code converts curl commands to Clojure code using clj-http. The conversion runs in your browser via WebAssembly for complete privacy. For Elixir, check our curl to Elixir converter. For Java, see curl to Java. Below are practical Clojure examples.
How to copy curl from your browser
- 1
Open DevTools
Press F12 or Ctrl+Shift+I to open your browser developer tools.
- 2
Go to the Network tab
Click the Network tab and perform the action that triggers the HTTP request.
- 3
Copy as cURL
Right-click the request → Copy → Copy as cURL. Then paste it above.
Frequently Asked Questions
What is clj-http?
clj-http is the most popular HTTP client library for Clojure, wrapping Apache HttpComponents. It provides an idiomatic, data-driven API with automatic JSON/EDN parsing, cookie management, and connection pooling. Add to project.clj: [clj-http "3.x"]. curl2code uses clj-http for all Clojure conversions.
clj-http vs http-kit vs aleph — which to use?
clj-http is synchronous, feature-rich, and the most widely used. http-kit is lightweight with async support, great for servers that also make HTTP calls. aleph is built on Netty for high-performance async I/O. For similar functional languages, see our curl to Elixir converter or curl to OCaml.
How to handle authentication in Clojure?
For Bearer auth, add headers: (client/get url {:headers {"Authorization" "Bearer token"}'}). For Basic auth, use the built-in option: {:basic-auth ["user" "pass"]}. clj-http also supports OAuth and digest auth. curl2code converts -u and header flags to idiomatic Clojure maps.
How to send multipart form data in Clojure?
Use the :multipart option: (client/post url {:multipart [{:name "file" :content (clojure.java.io/file "doc.pdf")} {:name "desc" :content "My file"}]}). clj-http handles boundary generation and Content-Type automatically. curl2code converts -F flags to this Clojure pattern.
How to handle HTTP errors in Clojure?
By default, clj-http throws ExceptionInfo on non-2xx responses. Disable with {:throw-exceptions false} to get the response map instead. Check (:status response). Use try/catch with ex-data to extract the response from exceptions.
How to make async HTTP requests in Clojure?
Use clj-http with {:async? true} which returns a future. Or use http-kit: (http/get url callback). For parallel requests, use pmap or core.async channels. Clojure futures run on the JVM thread pool. For similar concurrency, see curl to Java.
How to set timeouts in Clojure?
Pass timeout options: (client/get url {:connection-timeout 10000 :socket-timeout 30000}). Values are in milliseconds. For retries, use the :retry-handler option or wrap in a custom retry function with exponential backoff. These map to curl's --connect-timeout and --max-time.
How to use a proxy in Clojure?
Set proxy in the options map: (client/get url {:proxy-host "proxy" :proxy-port 8080}). For authenticated proxies: add :proxy-user and :proxy-pass. clj-http also supports SOCKS proxies. curl2code converts -x and --proxy flags to the correct Clojure proxy options.
How to send a POST request with JSON body in Clojure?
Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to Clojure using curl2code. The generated code uses (client/post url {:content-type :json :body (json/generate-string data)}). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the clj-http code.
How to add Bearer token authorization in Clojure?
Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates clj-http code with the auth header: :headers {'Authorization' 'Bearer YOUR_TOKEN'}. curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.
How to set Content-Type header in Clojure?
curl2code converts curl -H "Content-Type: application/json" URL to clj-http code with the proper header: :content-type :json. For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct clj-http API.