mirror of
https://github.com/foss42/apidash.git
synced 2025-05-25 02:06:44 +08:00
dart http codegen tests
This commit is contained in:
@ -7,27 +7,269 @@ void main() {
|
|||||||
|
|
||||||
group('GET Request', () {
|
group('GET Request', () {
|
||||||
test('GET 1', () {
|
test('GET 1', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com');
|
||||||
|
|
||||||
|
final response = await http.get(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
""";
|
""";
|
||||||
expect(dartHttpCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
expect(dartHttpCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GET 2', () {
|
test('GET 2', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com/country/data');
|
||||||
|
|
||||||
|
var queryParams = {
|
||||||
|
"code": "US"
|
||||||
|
};
|
||||||
|
uri = uri.replace(queryParameters: queryParams);
|
||||||
|
|
||||||
|
final response = await http.get(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
""";
|
""";
|
||||||
expect(dartHttpCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
expect(dartHttpCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('GET 3', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com/country/data?code=US');
|
||||||
|
|
||||||
|
var queryParams = {
|
||||||
|
"code": "IND"
|
||||||
|
};
|
||||||
|
var urlQueryParams = Map<String,String>.from(uri.queryParameters);
|
||||||
|
urlQueryParams.addAll(queryParams);
|
||||||
|
uri = uri.replace(queryParameters: urlQueryParams);
|
||||||
|
|
||||||
|
final response = await http.get(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET 4', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com/humanize/social');
|
||||||
|
|
||||||
|
var queryParams = {
|
||||||
|
"num": "8700000",
|
||||||
|
"digits": "3",
|
||||||
|
"system": "SS",
|
||||||
|
"add_space": "true",
|
||||||
|
"trailing_zeros": "true"
|
||||||
|
};
|
||||||
|
uri = uri.replace(queryParameters: queryParams);
|
||||||
|
|
||||||
|
final response = await http.get(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET 5', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.github.com/repos/foss42/apidash');
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"Authorization": "Bearer XYZ"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.get(uri,
|
||||||
|
headers: headers);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET 6', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.github.com/repos/foss42/apidash');
|
||||||
|
|
||||||
|
var queryParams = {
|
||||||
|
"raw": "true"
|
||||||
|
};
|
||||||
|
uri = uri.replace(queryParameters: queryParams);
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"Authorization": "Bearer XYZ"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.get(uri,
|
||||||
|
headers: headers);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET 7', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com');
|
||||||
|
|
||||||
|
final response = await http.get(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET 8', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.github.com/repos/foss42/apidash');
|
||||||
|
|
||||||
|
var queryParams = {
|
||||||
|
"raw": "true"
|
||||||
|
};
|
||||||
|
uri = uri.replace(queryParameters: queryParams);
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"Authorization": "Bearer XYZ"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.get(uri,
|
||||||
|
headers: headers);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('HEAD Request', () {
|
group('HEAD Request', () {
|
||||||
test('HEAD 1', () {
|
test('HEAD 1', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com');
|
||||||
|
|
||||||
|
final response = await http.head(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
""";
|
""";
|
||||||
expect(dartHttpCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
expect(dartHttpCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('HEAD 2', () {
|
test('HEAD 2', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('http://api.foss42.com');
|
||||||
|
|
||||||
|
final response = await http.head(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
""";
|
""";
|
||||||
expect(dartHttpCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
expect(dartHttpCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||||
});
|
});
|
||||||
@ -41,11 +283,11 @@ void main() async {
|
|||||||
var uri = Uri.parse('https://api.foss42.com/case/lower');
|
var uri = Uri.parse('https://api.foss42.com/case/lower');
|
||||||
|
|
||||||
String body = r'''{
|
String body = r'''{
|
||||||
"text":"lower I FLUTTER"
|
"text": "I LOVE Flutter"
|
||||||
}''';
|
}''';
|
||||||
|
|
||||||
var headers = {
|
var headers = {
|
||||||
"content-type": "application/json"
|
"content-type": "text/plain"
|
||||||
};
|
};
|
||||||
|
|
||||||
final response = await http.post(uri,
|
final response = await http.post(uri,
|
||||||
@ -67,18 +309,197 @@ void main() async {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('POST 2', () {
|
test('POST 2', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com/case/lower');
|
||||||
|
|
||||||
|
String body = r'''{
|
||||||
|
"text": "I LOVE Flutter"
|
||||||
|
}''';
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"content-type": "application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.post(uri,
|
||||||
|
headers: headers,
|
||||||
|
body: body);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
""";
|
""";
|
||||||
expect(dartHttpCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
expect(dartHttpCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('POST 3', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://api.foss42.com/case/lower');
|
||||||
|
|
||||||
|
String body = r'''{
|
||||||
|
"text": "I LOVE Flutter"
|
||||||
|
}''';
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"Authorization": "Bearer XYZ",
|
||||||
|
"content-type": "application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.post(uri,
|
||||||
|
headers: headers,
|
||||||
|
body: body);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
group('PUT Request', () {
|
||||||
|
test('PUT 1', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://reqres.in/api/users/2');
|
||||||
|
|
||||||
|
String body = r'''{
|
||||||
|
"name": "morpheus",
|
||||||
|
"job": "zion resident"
|
||||||
|
}''';
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"content-type": "application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.put(uri,
|
||||||
|
headers: headers,
|
||||||
|
body: body);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(dartHttpCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('PATCH Request', () {
|
||||||
|
test('PATCH 1', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://reqres.in/api/users/2');
|
||||||
|
|
||||||
|
String body = r'''{
|
||||||
|
"name": "marfeus",
|
||||||
|
"job": "accountant"
|
||||||
|
}''';
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"content-type": "application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.patch(uri,
|
||||||
|
headers: headers,
|
||||||
|
body: body);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
dartHttpCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('DELETE Request', () {
|
group('DELETE Request', () {
|
||||||
test('DELETE 1', () {
|
test('DELETE 1', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://reqres.in/api/users/2');
|
||||||
|
|
||||||
|
final response = await http.delete(uri);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
dartHttpCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
dartHttpCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('DELETE 2', () {
|
||||||
|
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
var uri = Uri.parse('https://reqres.in/api/users/2');
|
||||||
|
|
||||||
|
String body = r'''{
|
||||||
|
"name": "marfeus",
|
||||||
|
"job": "accountant"
|
||||||
|
}''';
|
||||||
|
|
||||||
|
var headers = {
|
||||||
|
"content-type": "application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.delete(uri,
|
||||||
|
headers: headers,
|
||||||
|
body: body);
|
||||||
|
|
||||||
|
int statusCode = response.statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
print('Status Code: $statusCode');
|
||||||
|
print('Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
print('Error Status Code: $statusCode');
|
||||||
|
print('Error Response Body: ${response.body}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
dartHttpCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ const requestModelGet5 = RequestModel(
|
|||||||
/// GET request model with headers & query params
|
/// GET request model with headers & query params
|
||||||
const requestModelGet6 = RequestModel(
|
const requestModelGet6 = RequestModel(
|
||||||
id: 'get6',
|
id: 'get6',
|
||||||
url: 'https://api.foss42.com/humanize/social',
|
url: 'https://api.github.com/repos/foss42/apidash',
|
||||||
method: HTTPVerb.get,
|
method: HTTPVerb.get,
|
||||||
requestHeaders: [
|
requestHeaders: [
|
||||||
NameValueModel(name: 'Authorization', value: 'Bearer XYZ'),
|
NameValueModel(name: 'Authorization', value: 'Bearer XYZ'),
|
||||||
@ -68,13 +68,28 @@ const requestModelGet6 = RequestModel(
|
|||||||
/// GET request model with body
|
/// GET request model with body
|
||||||
const requestModelGet7 = RequestModel(
|
const requestModelGet7 = RequestModel(
|
||||||
id: 'get7',
|
id: 'get7',
|
||||||
url: 'https://api.foss42.com/humanize/social',
|
url: 'https://api.foss42.com',
|
||||||
method: HTTPVerb.get,
|
method: HTTPVerb.get,
|
||||||
requestBodyContentType: ContentType.text,
|
requestBodyContentType: ContentType.text,
|
||||||
requestBody:
|
requestBody:
|
||||||
'This is a random text which should not be attached with a GET request',
|
'This is a random text which should not be attached with a GET request',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// GET request model with empty header & query param name
|
||||||
|
const requestModelGet8 = RequestModel(
|
||||||
|
id: 'get8',
|
||||||
|
url: 'https://api.github.com/repos/foss42/apidash',
|
||||||
|
method: HTTPVerb.get,
|
||||||
|
requestHeaders: [
|
||||||
|
NameValueModel(name: 'Authorization', value: 'Bearer XYZ'),
|
||||||
|
NameValueModel(name: '', value: 'Bearer XYZ'),
|
||||||
|
],
|
||||||
|
requestParams: [
|
||||||
|
NameValueModel(name: 'raw', value: 'true'),
|
||||||
|
NameValueModel(name: '', value: 'true'),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
/// Basic HEAD request model
|
/// Basic HEAD request model
|
||||||
const requestModelHead1 = RequestModel(
|
const requestModelHead1 = RequestModel(
|
||||||
id: 'head1',
|
id: 'head1',
|
||||||
@ -89,9 +104,19 @@ const requestModelHead2 = RequestModel(
|
|||||||
method: HTTPVerb.head,
|
method: HTTPVerb.head,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Basic POST request model
|
/// Basic POST request model (txt body)
|
||||||
const requestModelPost1 = RequestModel(
|
const requestModelPost1 = RequestModel(
|
||||||
id: 'post1',
|
id: 'post1',
|
||||||
|
url: 'https://api.foss42.com/case/lower',
|
||||||
|
method: HTTPVerb.post,
|
||||||
|
requestBody: r"""{
|
||||||
|
"text": "I LOVE Flutter"
|
||||||
|
}""",
|
||||||
|
requestBodyContentType: ContentType.text);
|
||||||
|
|
||||||
|
/// POST request model with JSON body
|
||||||
|
const requestModelPost2 = RequestModel(
|
||||||
|
id: 'post2',
|
||||||
url: 'https://api.foss42.com/case/lower',
|
url: 'https://api.foss42.com/case/lower',
|
||||||
method: HTTPVerb.post,
|
method: HTTPVerb.post,
|
||||||
requestBody: r"""{
|
requestBody: r"""{
|
||||||
@ -99,28 +124,59 @@ const requestModelPost1 = RequestModel(
|
|||||||
}""",
|
}""",
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with txt body
|
/// POST request model with headers
|
||||||
const requestModelPost2 = RequestModel(
|
const requestModelPost3 = RequestModel(
|
||||||
id: 'post1',
|
id: 'post3',
|
||||||
url: 'https://api.foss42.com/case/lower',
|
url: 'https://api.foss42.com/case/lower',
|
||||||
method: HTTPVerb.post,
|
method: HTTPVerb.post,
|
||||||
requestBody: r"""{
|
requestBody: r"""{
|
||||||
"text": "I LOVE Flutter"
|
"text": "I LOVE Flutter"
|
||||||
}""",
|
}""",
|
||||||
requestBodyContentType: ContentType.json,
|
requestBodyContentType: ContentType.json,
|
||||||
|
requestHeaders: [
|
||||||
|
NameValueModel(name: 'Authorization', value: 'Bearer XYZ'),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with headers
|
|
||||||
|
|
||||||
/// PUT request model
|
/// PUT request model
|
||||||
|
const requestModelPut1 = RequestModel(
|
||||||
|
id: 'put1',
|
||||||
|
url: 'https://reqres.in/api/users/2',
|
||||||
|
method: HTTPVerb.put,
|
||||||
|
requestBody: r"""{
|
||||||
|
"name": "morpheus",
|
||||||
|
"job": "zion resident"
|
||||||
|
}""",
|
||||||
|
requestBodyContentType: ContentType.json,
|
||||||
|
);
|
||||||
|
|
||||||
/// PATCH request model
|
/// PATCH request model
|
||||||
|
const requestModelPatch1 = RequestModel(
|
||||||
|
id: 'patch1',
|
||||||
|
url: 'https://reqres.in/api/users/2',
|
||||||
|
method: HTTPVerb.patch,
|
||||||
|
requestBody: r"""{
|
||||||
|
"name": "marfeus",
|
||||||
|
"job": "accountant"
|
||||||
|
}""",
|
||||||
|
requestBodyContentType: ContentType.json,
|
||||||
|
);
|
||||||
|
|
||||||
/// Basic DELETE request model
|
/// Basic DELETE request model
|
||||||
const requestModelDelete1 = RequestModel(
|
const requestModelDelete1 = RequestModel(
|
||||||
id: 'delete1',
|
id: 'delete1',
|
||||||
url: 'https://jsonplaceholder.typicode.com/posts/1',
|
url: 'https://reqres.in/api/users/2',
|
||||||
method: HTTPVerb.delete,
|
method: HTTPVerb.delete,
|
||||||
requestBody: '{"title": "foo","body": "bar","userId": 1}',
|
);
|
||||||
|
|
||||||
|
/// Basic DELETE with body
|
||||||
|
const requestModelDelete2 = RequestModel(
|
||||||
|
id: 'delete1',
|
||||||
|
url: 'https://reqres.in/api/users/2',
|
||||||
|
method: HTTPVerb.delete,
|
||||||
|
requestBody: r"""{
|
||||||
|
"name": "marfeus",
|
||||||
|
"job": "accountant"
|
||||||
|
}""",
|
||||||
requestBodyContentType: ContentType.json,
|
requestBodyContentType: ContentType.json,
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user