mirror of
https://github.com/foss42/apidash.git
synced 2025-06-27 19:07:40 +08:00
Fix http.client
This commit is contained in:
@ -36,7 +36,7 @@ print(data.decode("utf-8"))
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
for (final header in requestModel.requestHeaders!) {
|
for (final header in requestModel.requestHeaders!) {
|
||||||
result += """'${header.k}':'${header.v}',\n""";
|
result += """'${header.name}':'${header.value}',\n""";
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ print(data.decode("utf-8"))
|
|||||||
result += "?";
|
result += "?";
|
||||||
for (final queryParam in requestModel.requestParams!) {
|
for (final queryParam in requestModel.requestParams!) {
|
||||||
result +=
|
result +=
|
||||||
"${queryParam.k.toString().replaceAll(" ", "%20")}=${queryParam.v.toString().replaceAll(" ", "%20")}&";
|
"${queryParam.name.toString().replaceAll(" ", "%20")}=${queryParam.value.toString().replaceAll(" ", "%20")}&";
|
||||||
}
|
}
|
||||||
return result.substring(0, result.length - 1);
|
return result.substring(0, result.length - 1);
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ print(data.decode("utf-8"))
|
|||||||
if (requestModel.url.startsWith('http://') ||
|
if (requestModel.url.startsWith('http://') ||
|
||||||
requestModel.url.startsWith('https://')) {
|
requestModel.url.startsWith('https://')) {
|
||||||
result = requestModel.url.substring(requestModel.url.indexOf('://') + 3);
|
result = requestModel.url.substring(requestModel.url.indexOf('://') + 3);
|
||||||
}else{
|
} else {
|
||||||
result = requestModel.url;
|
result = requestModel.url;
|
||||||
}
|
}
|
||||||
Map<String, String> resultMap = {};
|
Map<String, String> resultMap = {};
|
||||||
|
@ -232,8 +232,8 @@ const kDefaultContentType = ContentType.json;
|
|||||||
|
|
||||||
enum CodegenLanguage {
|
enum CodegenLanguage {
|
||||||
dartHttp("Dart (http)", "dart", "dart"),
|
dartHttp("Dart (http)", "dart", "dart"),
|
||||||
kotlinOkHttp("Kotlin (okhttp3)", "java", "kt");
|
kotlinOkHttp("Kotlin (okhttp3)", "java", "kt"),
|
||||||
pythonHttpClient("Python (http.client)");
|
pythonHttpClient("Python (http.client)", "python", "py");
|
||||||
|
|
||||||
const CodegenLanguage(this.label, this.codeHighlightLang, this.ext);
|
const CodegenLanguage(this.label, this.codeHighlightLang, this.ext);
|
||||||
final String label;
|
final String label;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import 'package:apidash/codegen/python/pkg_http_client.dart';
|
import 'package:apidash/codegen/python/pkg_http_client.dart';
|
||||||
import 'package:apidash/models/models.dart' show KVRow, RequestModel;
|
import 'package:apidash/models/models.dart' show KVRow, RequestModel;
|
||||||
|
import 'package:apidash/models/name_value_model.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('PythonHttpClient', () {
|
group('PythonHttpClient', () {
|
||||||
final PythonHttpClient pythonHttpClient = PythonHttpClient();
|
final PythonHttpClient pythonHttpClient = PythonHttpClient();
|
||||||
|
|
||||||
test('getCode returns valid code for GET request', () {
|
test('getCode returns valid code for GET request', () {
|
||||||
const requestModel = RequestModel(
|
const requestModel = RequestModel(
|
||||||
@ -106,11 +107,11 @@ print(data.decode("utf-8"))
|
|||||||
url: 'https://jsonplaceholder.typicode.com/posts',
|
url: 'https://jsonplaceholder.typicode.com/posts',
|
||||||
method: HTTPVerb.get,
|
method: HTTPVerb.get,
|
||||||
requestParams: [
|
requestParams: [
|
||||||
KVRow('userId', 1),
|
NameValueModel(name: 'userId', value: 1),
|
||||||
],
|
],
|
||||||
requestHeaders: [
|
requestHeaders: [
|
||||||
KVRow('Custom-Header-1', 'Value-1'),
|
NameValueModel(name: 'Custom-Header-1', value: 'Value-1'),
|
||||||
KVRow('Custom-Header-2', 'Value-2')
|
NameValueModel(name: 'Custom-Header-2', value: 'Value-2')
|
||||||
],
|
],
|
||||||
id: '1',
|
id: '1',
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user