delete method

Future<bool> delete(
  1. String endpoint,
  2. dynamic identifier
)

Deletes a register on a specific endpoint.

Sends a DELETE request to delete a register identified by identifier on the specified endpoint.

Parameters:

  • endpoint: The API endpoint to send the request to.
  • identifier: The identifier to use as a key for deleting.

Returns:

A Future that completes with a boolean indicating whether the deletion was successful.

Implementation

Future<bool> delete(String endpoint, dynamic identifier) async {
  final parsedUrl = CoffeeUtil.concatUrl(baseUrl, endpoint);
  final url = identifier == null ? parsedUrl : CoffeeUtil.concatUrl(parsedUrl, identifier);
  final response = await httpClient.delete(Uri.parse(url), headers: CoffeeUtil.getHeaders());

  if(response.statusCode == 401) {
    Coffee.handleUnauthorizedError();
    await CoffeeStorage.clearLoggedUser();
  }

  CoffeeUtil.handleErrorMessage(response);

  return response.body.toLowerCase() == 'true';
}