request method Null safety
inherited
API request.
Returns a Map
with the response of the http request to the API
using the method
path
queryItems
and body
.
to build and perform the request.
Implementation
Future<Map<String, dynamic>> request(HTTPMethod method, String path,
{Map<String, dynamic>? queryItems, Map<String, dynamic>? body}) async {
final headers = getHeaders(body ?? {});
var encodedPath = "api/$apiVersion/partner/$path";
final url = Uri.https(baseUrl, encodedPath, queryItems);
switch (method) {
case HTTPMethod.get:
final getResponse = await httpClient.get(url, headers: headers);
return processResponse(getResponse);
case HTTPMethod.post:
final postResponse = await httpClient.post(url,
headers: headers, body: jsonEncode(body));
return processResponse(postResponse);
case HTTPMethod.put:
final putResponse =
await httpClient.put(url, headers: headers, body: jsonEncode(body));
return processResponse(putResponse);
case HTTPMethod.delete:
final deleteResponse = await httpClient.delete(url, headers: headers);
return processResponse(deleteResponse);
}
}