A utility to convert curl commands to VMware vRealize Orchestrator (vRO) JavaScript code.
Available as an npm package or a webapp

- Node.js 14.x or higher
- VMware vRealize Orchestrator environment for running the generated code
- npm 6.x or higher
- Installation
- Usage
- Features
- Examples
- API Reference
- Supported Curl Features
- License
- Author
- Contributing
- Development
npm install curl2vro
const curl2vRO = require('curl2vRO');
// Your curl command
const curlCommand = `curl https://api.example.com/data`;
// Convert to vRO code
const vroCode = curl2vRO.convertCurlToVRO(curlCommand);
console.log(vroCode);
The tool will generate a JavaScript file with the vRO code and save it in the current directory. The filename is derived from the hostname, path, and HTTP method.
- Converts curl commands to vRO JavaScript code
- Supports various HTTP methods (GET, POST, PUT, DELETE, etc.)
- Handles request headers
- Processes request body data (JSON, form data)
- Automatically generates appropriate filenames
- Adds JSDoc documentation to generated code
- Includes original curl command as a comment for reference
// Input
const curlCommand = `curl -X GET https://api.sampleapis.com/coffee/hot`;
// Output
/**
* @description Curl to vRO JavaScript converted code
* @author curl2vRO (Mayank Goyal)
*/
// Accept SSL certificate
var ld = Config.getKeystores().getImportCAFromUrlAction();
var model = ld.getModel();
model.value = "https://api.sampleapis.com/coffee/hot";
var error = ld.execute();
if (error) {
throw new Error("Failed to accept certificate for URL: " + "https://api.sampleapis.com/coffee/hot" + ". Error: " + error);
}
// Create transient REST host
var restHost = RESTHostManager.createHost("dynamicRequest");
var httpRestHost = RESTHostManager.createTransientHostFrom(restHost);
httpRestHost.operationTimeout = 600;
httpRestHost.url = "https://api.sampleapis.com";
// Create REST request
var request = httpRestHost.createRequest("GET", "/coffee/hot", null);
// Execute REST request
var response = request.execute();
// Handle response
if (response.statusCode == 200) {
System.log("Request successful");
var responseContent = JSON.parse(response.contentAsString);
System.log(JSON.stringify(responseContent));
} else {
throw "Request failed with status: " + response.statusCode;
}
/*
Original curl command:
curl -X GET https://api.sampleapis.com/coffee/hot
*/
// Input
const curlCommand = `curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer token123" \
-d '{"name": "John Doe", "email": "[email protected]"}'`;
// Output
/**
* @description Curl to vRO JavaScript converted code
* @author curl2vRO (Mayank Goyal)
*/
// Accept SSL certificate
var ld = Config.getKeystores().getImportCAFromUrlAction();
var model = ld.getModel();
model.value = "https://api.example.com/users";
var error = ld.execute();
if (error) {
throw new Error("Failed to accept certificate for URL: " + "https://api.example.com/users" + ". Error: " + error);
}
// Create transient REST host
var restHost = RESTHostManager.createHost("dynamicRequest");
var httpRestHost = RESTHostManager.createTransientHostFrom(restHost);
httpRestHost.operationTimeout = 600;
httpRestHost.url = "https://api.example.com";
// Create REST request
var request = httpRestHost.createRequest("POST", "/users", JSON.stringify({"name": "John Doe", "email": "[email protected]"}));
// Add headers
request.setHeader("Content-Type", "application/json");
request.setHeader("Authorization", "Bearer token123");
// Execute REST request
var response = request.execute();
// Handle response
if (response.statusCode == 200) {
System.log("Request successful");
var responseContent = JSON.parse(response.contentAsString);
System.log(JSON.stringify(responseContent));
} else {
throw "Request failed with status: " + response.statusCode;
}
/*
Original curl command:
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer token123" \
-d '{"name": "John Doe", "email": "john@example.com"}'
*/
// Input
const curlCommand = `curl --location --request PUT 'https://api.example.com/resources/123' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic dXNlcjpwYXNzd29yZA==' \
--data-raw '{
"title": "Updated Resource",
"status": "active",
"priority": 1
}'`;
// Output
/**
* @description Curl to vRO JavaScript converted code
* @author curl2vRO (Mayank Goyal)
*/
// Accept SSL certificate
var ld = Config.getKeystores().getImportCAFromUrlAction();
var model = ld.getModel();
model.value = "https://api.example.com/resources/123";
var error = ld.execute();
if (error) {
throw new Error("Failed to accept certificate for URL: " + "https://api.example.com/resources/123" + ". Error: " + error);
}
// Create transient REST host
var restHost = RESTHostManager.createHost("dynamicRequest");
var httpRestHost = RESTHostManager.createTransientHostFrom(restHost);
httpRestHost.operationTimeout = 600;
httpRestHost.url = "https://api.example.com";
// Create REST request
var request = httpRestHost.createRequest("PUT", "/resources/123", JSON.stringify({
"title": "Updated Resource",
"status": "active",
"priority": 1
}));
// Add headers
request.setHeader("Content-Type", "application/json");
request.setHeader("Authorization", "Basic dXNlcjpwYXNzd29yZA==");
// Execute REST request
var response = request.execute();
// Handle response
if (response.statusCode == 200) {
System.log("Request successful");
var responseContent = JSON.parse(response.contentAsString);
System.log(JSON.stringify(responseContent));
} else {
throw "Request failed with status: " + response.statusCode;
}
/*
Original curl command:
curl --location --request PUT 'https://api.example.com/resources/123' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic dXNlcjpwYXNzd29yZA==' \
--data-raw '{
"title": "Updated Resource",
"status": "active",
"priority": 1
}'
*/
// Input
const curlCommand = `curl -X DELETE https://api.example.com/users/123 \
-H "Authorization: Bearer token123"`;
// Output
/**
* @description Curl to vRO JavaScript converted code
* @author curl2vRO (Mayank Goyal)
*/
// Accept SSL certificate
var ld = Config.getKeystores().getImportCAFromUrlAction();
var model = ld.getModel();
model.value = "https://api.example.com/users/123";
var error = ld.execute();
if (error) {
throw new Error("Failed to accept certificate for URL: " + "https://api.example.com/users/123" + ". Error: " + error);
}
// Create transient REST host
var restHost = RESTHostManager.createHost("dynamicRequest");
var httpRestHost = RESTHostManager.createTransientHostFrom(restHost);
httpRestHost.operationTimeout = 600;
httpRestHost.url = "https://api.example.com";
// Create REST request
var request = httpRestHost.createRequest("DELETE", "/users/123", null);
// Add headers
request.setHeader("Authorization", "Bearer token123");
// Execute REST request
var response = request.execute();
// Handle response
if (response.statusCode == 200) {
System.log("Request successful");
var responseContent = JSON.parse(response.contentAsString);
System.log(JSON.stringify(responseContent));
} else {
throw "Request failed with status: " + response.statusCode;
}
/*
Original curl command:
curl -X DELETE https://api.example.com/users/123 \
-H "Authorization: Bearer token123"
*/
// Input
const curlCommand = `curl "https://api.example.com/search?q=test&limit=10" \
-H "Accept: application/json"`;
// Output
/**
* @description Curl to vRO JavaScript converted code
* @author curl2vRO (Mayank Goyal)
*/
// Accept SSL certificate
var ld = Config.getKeystores().getImportCAFromUrlAction();
var model = ld.getModel();
model.value = "https://api.example.com/search?q=test&limit=10";
var error = ld.execute();
if (error) {
throw new Error("Failed to accept certificate for URL: " + "https://api.example.com/search?q=test&limit=10" + ". Error: " + error);
}
// Create transient REST host
var restHost = RESTHostManager.createHost("dynamicRequest");
var httpRestHost = RESTHostManager.createTransientHostFrom(restHost);
httpRestHost.operationTimeout = 600;
httpRestHost.url = "https://api.example.com";
// Create REST request
var request = httpRestHost.createRequest("GET", "/search?q=test&limit=10", null);
// Add headers
request.setHeader("Accept", "application/json");
// Execute REST request
var response = request.execute();
// Handle response
if (response.statusCode == 200) {
System.log("Request successful");
var responseContent = JSON.parse(response.contentAsString);
System.log(JSON.stringify(responseContent));
} else {
throw "Request failed with status: " + response.statusCode;
}
/*
Original curl command:
curl "https://api.example.com/search?q=test&limit=10" \
-H "Accept: application/json"
*/
Converts a curl command to vRO JavaScript code and saves it to a file.
- Parameters
curlCommand
(string): The curl command to convert
- Returns
- (string): The generated vRO JavaScript code
Parses a curl command and extracts its components.
- Parameters
curlCommand
(string): The curl command to parse
- Returns
- (Object): An object containing the parsed components (url, method, headers, data)
Generates vRO JavaScript code from parsed curl command components.
- Parameters
parsedCurl
(Object): The parsed curl command componentsurl
(string): The URL from the curl commandmethod
(string): The HTTP method (GET, POST, etc.)headers
(Object): The HTTP headers as key-value pairsdata
(string|null): The request body data (if any)
originalCurlCommand
(string): The original curl command for reference
- Returns
- (string): The generated vRO JavaScript code
- HTTP methods: GET, POST, PUT, DELETE, PATCH, etc.
- Request headers with
-H
or--header
- Request body data with
-d
,--data
,--data-raw
,--data-binary
- URL specification with or without quotes
- Basic authentication
- Form data
This project is licensed under the MIT License - see the LICENSE file for details.
Mayank Goyal
Website: cloudblogger.co.in
Email: [email protected]
Contributions are welcome! Please feel free to submit a Pull Request.
To set up the development environment:
# Clone the repository
git clone https://github.com/yourusername/curl2vro.git
# Install dependencies
cd curl2vro
npm install
# Run tests
npm test