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
- Example of use:
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:- Multiple HTTP Library
- HttpClient (Java 11+)
- OkHttp
- HttpUrlConnection
- Jsoup
- Complete HTTP functions
- GET/POST/PUT/DELETE and other methods
- Request headers (Headers)
- Request body (Body)
- Cookie
- Authentication information
- 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:| Method | Single cURL conversion | Batch conversion (10) |
|---|---|---|
| Handwritten code | 5 minutes | 50 minutes |
| Using tools | 10 seconds | 2 minutes |
| Efficiency improvement | 30 times | 25 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:- Solve real problems
- No fancy but useless functions
- Each tool has clear usage scenarios
- Simplify the development process
- Automate repetitive work
- Let developers focus on business logic
- Improve work efficiency
- 10 times or more efficiency improvement
- Reduce the probability of errors
- 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:- cURL to Python
- cURL to JavaScript
- cURL to Go
- Reverse function: code to cURL
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.