delete method

Future<Response> delete(
  1. String endpoint, {
  2. dynamic body,
  3. dynamic query,
})

Sends an HTTP DELETE request to the specified endpoint.

This method is used to remove a resource. It can optionally include a request body and query parameters. Any exceptions encountered during the request will be re-thrown.

To delete a user with a specific ID:

try {
  final response = await apiService.delete('/users/123');
  print('User deleted successfully');
} on DioException catch (e) {
  print('Error deleting user: $e');
}

Parameters:

  • endpoint: The URL path or the full URL for the request (e.g., '/users/123').
  • body: Optional request body.
  • query: Optional query parameters. Typically a Map<String, dynamic>.

Returns:

  • A Future<Response> that completes with the server's response.

Throws:

  • Any DioException (or other exceptions) that occur during the request.

Implementation

Future<Response> delete(String endpoint,
    {dynamic body, dynamic query}) async {
  try {
    return await _dio.delete(endpoint, data: body, queryParameters: query);
  } catch (e) {
    rethrow;
  }
}