diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 72b57468..bca76b79 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -8,4 +8,5 @@ export 'http_utils.dart'; export 'js_utils.dart'; export 'save_utils.dart'; export 'ui_utils.dart'; +export 'validation_utils.dart'; export 'window_utils.dart'; diff --git a/lib/utils/validation_utils.dart b/lib/utils/validation_utils.dart new file mode 100644 index 00000000..261faa08 --- /dev/null +++ b/lib/utils/validation_utils.dart @@ -0,0 +1,18 @@ +import 'package:apidash_core/apidash_core.dart'; + +String? getValidationResult(HttpRequestModel requestModel) { + if (requestModel.url.trim().isEmpty) { + return 'Request URL is empty. Please provide a valid URL.'; + } + if (requestModel.method == HTTPVerb.get && requestModel.hasAnyBody) { + return 'GET request contains a body. This is not supported.'; + } + if (requestModel.hasJsonData) { + try { + kJsonDecoder.convert(requestModel.body!); + } catch (e) { + return 'Invalid JSON in request body: ${e.toString()}'; + } + } + return null; +}