patch method
Sends a PATCH request to the specified endpoint with the provided body as JSON.
Returns the response data if the request is successful.
If an error occurs, it is handled by _handleError.
endpoint: The API endpoint to send the PATCH request to.
body: The data to be sent in the request body, which will be JSON-encoded.
Implementation
Future<dynamic> patch(
String endpoint,
dynamic body, {
Map<String, dynamic> query = const {},
CancelToken? cancelToken,
Options? options,
Function(int, int)? onSendProgress,
Function(int, int)? onReceiveProgress,
}) async {
try {
final response = await _dio.patch(
endpoint,
data: jsonEncode(body),
queryParameters: query,
options: options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
if (isApiLoggerEnable) {
await _sqfLiteService.add(data: {
"url": response.realUri.toString(),
"request": jsonEncode(response.requestOptions.data),
"response": jsonEncode(response.data),
"statusCode": response.statusCode,
"error": "No Error",
"header": jsonEncode(response.headers.map),
"method": response.requestOptions.method,
"timestamp" : DateTime.now().toIso8601String(),
});
}
return response.data;
} catch (e) {
return _handleError(e);
}
}