cURL to Groovy Converter
Convert curl commands to Groovy code using java.net.http. Paste a command and the Groovy 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 Groovy java.net.http code appears instantly.
- Set up: Install Groovy 3 or later on Java 11 or later. No libraries are needed.
- Run it: Save the code as
request.groovyand rungroovy request.groovy. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no java.net.http equivalent.
Example
GET with headers → Groovy java.net.http
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
def client = HttpClient.newHttpClient()
def request = HttpRequest.newBuilder(URI.create('https://api.example.com/v1/users?page=2'))
.header('Accept', 'application/json')
.header('Authorization', 'Bearer YOUR_TOKEN')
.method('GET', HttpRequest.BodyPublishers.noBody())
.build()
def response = client.send(request, HttpResponse.BodyHandlers.ofString())
println response.statusCode()
println response.body()Common use cases
- Jenkins pipelines and Gradle build scripts
- Groovy scripts and Grails apps
Converting curl to Groovy java.net.http
The Groovy code uses java.net.http.HttpClient, the HTTP client built into Java 11 and later, so it runs without extra dependencies. Strings are single-quoted, so $ in URLs or tokens isn't treated as interpolation.
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 java.net.http code. Options that have no java.net.http equivalent are listed under the editors rather than silently dropped.
Limitations
- java.net.http has no multipart helper, so file uploads are built by hand in the code.
- 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
Why single-quoted strings?
Double-quoted Groovy strings are GStrings: $name inside them is replaced with a variable. Single quotes keep values such as tokens exactly as written.
Does this work in a Jenkins pipeline?
In a sandboxed pipeline, these Java classes may need script approval. The HTTP Request plugin's httpRequest step is an alternative there.
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.