Forum Discussion

klitchev's avatar
klitchev
Occasional Contributor
13 years ago

JSON parameters and POST request parameter handling

SoapUI is the best for simple POST requests, but totally misses the point when it comes to REST+JSON. Given the great way it handles parameters from resources down to the request level, it would be cool to:

- Add possibility to be able to fetch parameter values in a POST request body from the resource/method parameters. I.e., use right click in POST request body -> Get Data -> All parameters (not only Project level custom properties)
- Add JSON parameter style, which converts a |Key|Value| pair to "key":"value" for strings and "key":value for integers/boolean and is not eligible for query submission in the URL

This way it will be possible to better handle JSON REST tests.

Sample PLAIN parameters handling in POST REST request
A sample work flow will be:
1. Create REST resource and define some PLAIN style parameters
2. Add a method
3. Create a POST request
4. In the POST request body shape up a JSON template and use the PLAIN parameters as data source from the REST resource. Here SoapUI would simply get the value from the PLAIN parameter and the user will need to shape up the JSON object tags and layout

Given a REST Resource parameter:
- named "parameterNameFormResourceOrMethod" with value "12345" of type PLAIN
and the following POST request body:
{
"key": "${parameterNameFormResourceOrMethod}"
}

then SoapUI will produce the following POST request body:
{
"key": "12345"
}


Better approach to JSON POST requests
1. Create REST resource and define some JSON style parameters
2. Add a method
3. Create a POST request
4. Create the basic JSON request POST body and add the parameter name. SoapUI will create the proper key:value pair according to the JSON notation and parameter type.

Given the following REST Resource parameters
- Parameter named "paramName1" with value "someString" of style JSON with type String
- Parameter named "paramName2" with value "12345" of style JSON with type Integer
and the following POST request body:
{
${paramName1},
${paramName2},
}

then SoapUI will produce the following POST request body:
{
"paramName1":"someString",
"paramName2":12345
}

12 Replies