requestToCurl static method
Implementation
static String requestToCurl(Request request) {
// Start building the cURL command
final List<String> curlCommand = ['curl'];
curlCommand.add('-X ${request.method}');
// Add the headers
if (request.headers.isNotEmpty) {
final headersString = request.headers.map((key, value) {
return '-H "$key: $value"';
}).join(' ');
curlCommand.add(headersString);
}
// Add the request data if it exists
if (request.data != null) {
final jsonData = json.encode(request.data);
curlCommand.add('-d \'$jsonData\'');
}
// Add the URI
curlCommand.add('\'${request.uri}\'');
// Join all parts into a single string
final curlString = curlCommand.join(' ');
return curlString;
}