From cURL to Java code: the automated conversion tool we developed

A request from a user I received feedback from users last week: "Does your tool have the function of converting cURL to Java code? I often need to convert the cURL commands exported by Postman into Java code. Handwriting is too slow." This requirement is very typical. We checked Tool Junk's code category and found that this feature is not yet available. So we decided to develop this tool at Tool Junk.

A request from users

I received feedback from users last week: "Does your tool have the function of converting cURL to Java code? I often need to convert cURL commands exported by Postman into Java code. Handwriting is too slow." This requirement is very typical. We checked Tool Junk's code category and found that this feature is not yet available. So we decided to develop this tool at Tool Junk.

How we implement this tool

The requirements are very clear:
  • Input: cURL command string
  • Output: Java HTTP client code
  • Support: HttpClient, OkHttp, HttpUrlConnection and other libraries
We implemented this function on the cURL to Java Converter of tool fans.
  • Example of use:
Enter cURL command:
curl -X POST https://api.example.com/users \
  • -H "Content-Type: application/json" \
  • -H "Authorization: Bearer token123" \
  • -d '{"name":"Zhang San","email":"[email protected]"}'
The tool automatically generates Java code:
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.example.com/users"))
    .header("Content-Type", "application/json")
    .header("Authorization", "Bearer token123")
    .POST(HttpRequest.BodyPublishers.ofString("{\"name\":\"张三\",\"email\":\"[email protected]\"}"))
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Features of the tool

This tool we developed supports:
  1. Multiple HTTP Library
  • HttpClient (Java 11+)
  • OkHttp
  • HttpUrlConnection
  • Jsoup
  1. Complete HTTP functions
  • GET/POST/PUT/DELETE and other methods
  • Request headers (Headers)
  • Request body (Body)
  • Cookie
  • Authentication information
  1. Smart parsing
  • Automatic identification of URLs
  • Parse JSON Data
  • Handle special characters
  • Preserve original format

Efficiency improvement: 5 minutes → 10 seconds

We compared the efficiency of manual conversion and tool conversion:
MethodSingle cURL conversionBatch conversion (10)
Handwritten code5 minutes50 minutes
Using tools10 seconds2 minutes
Efficiency improvement30 times25 times

Actual application scenarios

Scenario 1: Convert API documents to code

Backend colleagues send cURL example:
curl -X GET "https://api.example.com/orders?status=completed" \
  • -H "X-API-Key: abc123"
After conversion with the tool, the usable Java code is directly obtained without manual splicing.

Scenario 2: Postman export

After testing the interface in Postman, right-click to copy the cURL and paste it into the tool to get the Java calling code immediately.

Scenario 3: Quick debugging and reproduction

When troubleshooting online, copy the cURL from the browser developer tools and convert it into Java code to reproduce the problem locally.

Our design philosophy

When developing various tools of Tool Fans, we always adhere to:
  1. Solve real problems
  • No fancy but useless functions
  • Each tool has clear usage scenarios
  1. Simplify the development process
  • Automate repetitive work
  • Let developers focus on business logic
  1. Improve work efficiency
  • 10 times or more efficiency improvement
  • Reduce the probability of errors
  1. Support multiple languages
  • Tool Fans support 7 Languages
  • Serving global developers

Follow-up plans

Based on user feedback, we plan to continue to add on Tools:
  1. cURL to Python
  2. cURL to JavaScript
  3. cURL to Go
  4. Reverse function: code to cURL
If you have other needs, you can also give us feedback on Tools. We continue to create more useful tools for developers.
If you are also doing API integration, or often need to convert cURL commands into Java code, try this tool we developed. Maybe it can save you a lot of time.