DELETE-ing data
In this recipe, you will learn how to perform a DELETE action on a web service. This is useful when your apps need to delete existing data from a web service.
Getting ready
- To follow along with this recipe, you must have completed the code in the previous recipe.
How to do it...
To perform a DELETE action on a web service, follow these steps:
- Log into the Wiremock service at https://app.wiremock.cloud and click on the
Stubs
section of the example API. Then, create a new Stub. - Complete the request, with the following data:
- Name:
Delete Pizza
- Verb: DELETE
- Address:
/pizza
- Status:
200
- Bpdy Type:
json
- Body:
{"message": "Pizza was deleted"}
- Name:
- Save the new Stub
- In the Flutter project, add a
deletePizza
method to theHttpHelper
class in thehttp_helper.dart
file:
Future<String> deletePizza(int id) async {
const deletePath = '/pizza';
Uri url = Uri.https(authority, deletePath);
http.Response r = await http.delete(
...