POST-ing data
In this recipe, you will learn how to perform a POST action on a web service. This is useful whenever you are connecting to web services that not only provide data but also allow you to change the information stored on the server-side. Usually, you will have to provide some form of authentication to the service, but for this recipe, as we are using a mock service, this will not be necessary.
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 POST action on a web service, follow these steps :
- Log into the Mock Lab 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:
Post Pizza
- Verb:
POST
- Address:
/pizza
- Status:
201
- Body type
: json
- Body:
{"message": "The pizza was posted"}
- Name:
- Press the Save button.
- In the Flutter project, in the
httpHelper.dart
file, in theHttpHelper...