Skip to content

Add feature Websocket Support #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,13 @@ final kColorHttpMethodDelete = Colors.red.shade800;

enum RequestItemMenuOption { edit, delete, duplicate }

enum ProtocolType { http, websocket }

enum HTTPVerb { get, head, post, put, patch, delete }

enum FormDataType { text, file }

const kSupportedUriSchemes = ["https", "http"];
const kSupportedUriSchemes = ["https", "http", "ws", "wss"];
const kDefaultUriScheme = "https";
const kMethodsWithBody = [
HTTPVerb.post,
Expand All @@ -254,7 +256,9 @@ const kMethodsWithBody = [
HTTPVerb.delete,
];

const kDefaultProtocolType = ProtocolType.http;
const kDefaultHttpMethod = HTTPVerb.get;

const kDefaultContentType = ContentType.json;

enum CodegenLanguage {
Expand Down Expand Up @@ -497,6 +501,10 @@ const kLabelPlusNew = "+ New";
const kLabelSend = "Send";
const kLabelSending = "Sending..";
const kLabelBusy = "Busy";
const kLabelConnect = "Connect";
const kLabelConnecting = "Connecting..";
const kLabelDisconnect = "Disconnect";

const kLabelCopy = "Copy";
const kLabelSave = "Save";
const kLabelDownload = "Download";
2 changes: 2 additions & 0 deletions lib/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export 'request_model.dart';
export 'response_model.dart';
export 'settings_model.dart';
export 'form_data_model.dart';
export 'websocket/request_model.dart';
export 'websocket/response_model.dart';
28 changes: 27 additions & 1 deletion lib/models/request_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RequestModel {
const RequestModel({
required this.id,
this.method = HTTPVerb.get,
this.protocol = ProtocolType.http,
this.url = "",
this.name = "",
this.description = "",
Expand All @@ -28,10 +29,12 @@ class RequestModel {
this.requestFormDataList,
this.responseStatus,
this.message,
this.websocketMessageBody,
this.responseModel,
});

final String id;
final ProtocolType protocol;
final HTTPVerb method;
final String url;
final String name;
Expand All @@ -46,6 +49,7 @@ class RequestModel {
final List<FormDataModel>? requestFormDataList;
final int? responseStatus;
final String? message;
final String? websocketMessageBody;
final ResponseModel? responseModel;

List<NameValueModel>? get enabledRequestHeaders =>
Expand All @@ -72,6 +76,7 @@ class RequestModel {
}) {
return RequestModel(
id: id,
protocol: protocol,
method: method,
url: url,
name: "$name (copy)",
Expand All @@ -91,6 +96,7 @@ class RequestModel {

RequestModel copyWith({
String? id,
ProtocolType? protocol,
HTTPVerb? method,
String? url,
String? name,
Expand All @@ -105,6 +111,7 @@ class RequestModel {
List<FormDataModel>? requestFormDataList,
int? responseStatus,
String? message,
String? websocketMessageBody,
ResponseModel? responseModel,
}) {
var headers = requestHeaders ?? this.requestHeaders;
Expand All @@ -113,6 +120,7 @@ class RequestModel {
var enabledParams = isParamEnabledList ?? this.isParamEnabledList;
return RequestModel(
id: id ?? this.id,
protocol: protocol ?? this.protocol,
method: method ?? this.method,
url: url ?? this.url,
name: name ?? this.name,
Expand All @@ -128,16 +136,23 @@ class RequestModel {
requestFormDataList: requestFormDataList ?? this.requestFormDataList,
responseStatus: responseStatus ?? this.responseStatus,
message: message ?? this.message,
websocketMessageBody: websocketMessageBody ?? this.websocketMessageBody,
responseModel: responseModel ?? this.responseModel,
);
}

factory RequestModel.fromJson(Map<String, dynamic> data) {
ProtocolType protocol;
HTTPVerb method;
ContentType requestBodyContentType;
ResponseModel? responseModel;

final id = data["id"] as String;
try {
protocol = ProtocolType.values.byName(data["protocol"] as String);
} catch (e) {
protocol = kDefaultProtocolType;
}
try {
method = HTTPVerb.values.byName(data["method"] as String);
} catch (e) {
Expand All @@ -160,6 +175,7 @@ class RequestModel {
final requestFormDataList = data["requestFormDataList"];
final responseStatus = data["responseStatus"] as int?;
final message = data["message"] as String?;
final websocketMessageBody = data["websocketMessageBody"] as String?;
final responseModelJson = data["responseModel"];

if (responseModelJson != null) {
Expand All @@ -171,6 +187,7 @@ class RequestModel {

return RequestModel(
id: id,
protocol: protocol,
method: method,
url: url,
name: name ?? "",
Expand All @@ -191,13 +208,15 @@ class RequestModel {
: null,
responseStatus: responseStatus,
message: message,
websocketMessageBody: websocketMessageBody,
responseModel: responseModel,
);
}

Map<String, dynamic> toJson({bool includeResponse = true}) {
return {
"id": id,
"protocol": protocol.name,
"method": method.name,
"url": url,
"name": name,
Expand All @@ -211,6 +230,7 @@ class RequestModel {
"requestFormDataList": rowsToFormDataMapList(requestFormDataList),
"responseStatus": includeResponse ? responseStatus : null,
"message": includeResponse ? message : null,
"websocketMessageBody": includeResponse ? websocketMessageBody : null,
"responseModel": includeResponse ? responseModel?.toJson() : null,
};
}
Expand All @@ -219,6 +239,7 @@ class RequestModel {
String toString() {
return [
"Request Id: $id",
"Request Protocol: ${protocol.name}",
"Request Method: ${method.name}",
"Request URL: $url",
"Request Name: $name",
Expand All @@ -233,7 +254,8 @@ class RequestModel {
"Request FormData: ${requestFormDataList.toString()}",
"Response Status: $responseStatus",
"Response Message: $message",
"Response: ${responseModel.toString()}"
"Websocket Message Body: $websocketMessageBody"
"Response: ${responseModel.toString()}"
].join("\n");
}

Expand All @@ -242,6 +264,7 @@ class RequestModel {
return other is RequestModel &&
other.runtimeType == runtimeType &&
other.id == id &&
other.protocol == protocol &&
other.method == method &&
other.url == url &&
other.name == name &&
Expand All @@ -256,6 +279,7 @@ class RequestModel {
other.requestFormDataList == requestFormDataList &&
other.responseStatus == responseStatus &&
other.message == message &&
other.websocketMessageBody == websocketMessageBody &&
other.responseModel == responseModel;
}

Expand All @@ -264,6 +288,7 @@ class RequestModel {
return Object.hash(
runtimeType,
id,
protocol,
method,
url,
name,
Expand All @@ -278,6 +303,7 @@ class RequestModel {
requestFormDataList,
responseStatus,
message,
websocketMessageBody,
responseModel,
);
}
Expand Down
Loading