lundi 13 août 2018

Does Postman support controlling format of request body?

I am considering using Postman for automating my testing of REST API and have been using it for only a few days. So far, I've created an adequate amount of requests for my initial collection. I have made use of global, environment, and collection variables in my pre-request scripts, tests, and bodies of my requests as well. I'm looking to control which properties are included in the request without making several copies of the same request to exclude some properties.

For example, I have a JSON request body as such:

{
    "Username": "",
    "Password": "",
    "AnotherProperty": ""
}

In the event that 'AnotherProperty' is null or empty, I would like to remove the property entirely from the request. I only want 'AnotherProperty' to be included in the request if it has a value. Thus, if null or empty the request should appear as:

{
    "Username": "",
    "Password": ""
}

The only way I found to complete this is to save separate requests both with and without the property in the collection, but this does not seem efficient to do for every property in the request when there are many properties. Is it possible to control the properties included in the request if their values are null or empty?

Aucun commentaire:

Enregistrer un commentaire