mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
request validation utils
This commit is contained in:
18
lib/utils/validation_utils.dart
Normal file
18
lib/utils/validation_utils.dart
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user