PUT-ting data
In this recipe, you will learn how to perform a PUT action on a web service. This is useful when your apps need to edit existing data in a web service.
Getting ready
- To follow along with this recipe, you need to have completed the code in the previous recipe.
How to do it...
To perform a PUT 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, as follows:
- Name:
Put Pizza
- Verb: PUT
- Address:
/pizza
- Status:
200
- Body Type:
json
- Body:
{"message": "Pizza was updated"}
- Name:
- Click the “Save” button
- In the Flutter project, add a
putPizza
method to theHttpHelper
class in thehttp_helper.dart
file:
Future<String> putPizza(Pizza pizza) async {
const putPath = '/pizza';
String put = json.encode(pizza.toJson());
Uri url = Uri.https(authority, putPath);
http.Response...