getCurl method
Generates a cURL command string from a CurlModel request.
This method constructs a cURL command using the HTTP method, headers, body, and URL from the provided CurlModel request.
Returns a String representing the cURL command.
Implementation
String getCurl(CurlModel request) {
final stringBuilder = StringBuffer()..write('curl -X ${request.method}');
request.headers.forEach((key, value) {
if (key.toLowerCase() != 'content-length') {
stringBuilder.write(' -H "$key: $value"');
}
});
if (request.body != null && request.body.isNotEmpty) {
stringBuilder.write(' -d \'${getCurlInputBody(request.body)}\'');
}
stringBuilder.write(' "${request.url}"');
return stringBuilder.toString();
}