call method
Future
call(
- RESTOption option, {
- required String resource,
- required dynamic headers,
- String? body,
Implementation
Future<dynamic> call(
RESTOption option, {
required String resource,
required headers,
String? body,
}) async {
dynamic responseJson;
http.Response response;
try {
switch (option) {
case RESTOption.get:
response =
await http.get(Uri.parse(_baseUrl + resource), headers: headers);
break;
case RESTOption.post:
response = await http.post(
Uri.parse(_baseUrl + resource),
headers: headers,
body: body,
);
break;
case RESTOption.patch:
response = await http.patch(
Uri.parse(_baseUrl + resource),
headers: headers,
body: body,
);
break;
case RESTOption.delete:
response = await http.delete(
Uri.parse(_baseUrl + resource),
headers: headers,
body: body,
);
break;
}
responseJson = _returnResponse(response);
} on SocketException {
throw FetchDataException('No Internet connection');
}
return responseJson;
}