getEnvironmentMethod function
Future Function(Uri url, {dynamic body, Map<String, String> ? headers})
getEnvironmentMethod(
- Client client,
- MakeRequestMethod method
Maps our MakeRequestMethod enum to the corresponding client method
Implementation
Future<dynamic> Function(
Uri url, {
Map<String, String>? headers,
dynamic body,
}) getEnvironmentMethod(http.Client client, MakeRequestMethod method) {
switch (method) {
case MakeRequestMethod.get:
// normalize this method to make sure the addition of `body` does not
// end up producing type issues
return (
Uri url, {
Map<String, String>? headers,
dynamic body,
}) {
return client.get(url, headers: headers);
};
case MakeRequestMethod.put:
return (
Uri url, {
Map<String, String>? headers,
dynamic body,
}) {
return client.put(url, headers: headers, body: jsonEncode(body));
};
case MakeRequestMethod.delete:
return (
Uri url, {
Map<String, String>? headers,
dynamic body,
}) {
return client.delete(url, headers: headers, body: jsonEncode(body));
};
case MakeRequestMethod.post:
return (
Uri url, {
Map<String, String>? headers,
dynamic body,
}) {
final bodyResult = jsonEncode(body);
return client.post(url, headers: headers, body: bodyResult);
};
default:
throw Exception('Request method $method is not defined');
}
}