Files
apidash/lib/models/request_model.dart
Udhay-Adithya fadf49372f feat: add support for pre-request scripts
Introduces `preRequestScript` and `postRequestScript` fields to the request model to store user-defined scripts.

Implements a service using `flutter_js` to execute JavaScript pre-request scripts before a request is sent.
The script can access and modify request data (like headers, body, URL) and environment variables.

Adds bridging to forward JavaScript `console.log`, `console.warn`, and `console.error` calls to the Dart console for easier debugging
2025-04-25 23:26:31 +05:30

32 lines
926 B
Dart

import 'package:apidash_core/apidash_core.dart';
part 'request_model.freezed.dart';
part 'request_model.g.dart';
@freezed
class RequestModel with _$RequestModel {
@JsonSerializable(
explicitToJson: true,
anyMap: true,
)
const factory RequestModel({
required String id,
@Default(APIType.rest) APIType apiType,
@Default("") String name,
@Default("") String description,
@JsonKey(includeToJson: false) @Default(0) requestTabIndex,
HttpRequestModel? httpRequestModel,
int? responseStatus,
String? message,
HttpResponseModel? httpResponseModel,
@JsonKey(includeToJson: false) @Default(false) bool isWorking,
@JsonKey(includeToJson: false) DateTime? sendingTime,
@Default("") String preRequestScript,
@Default("") String postRequestScript,
}) = _RequestModel;
factory RequestModel.fromJson(Map<String, Object?> json) =>
_$RequestModelFromJson(json);
}