Send and receive a JSON request for a REST service

Relevant for: API testing only

Note: The following tasks show how to send a single JSON request to a REST service method step (after it has been added to the canvas). To create a reusable model, create a prototype. For details, see Create a REST service model.

Set the HTTP properties

Note: If you are working with an API test created in UFT 11.51 or earlier or Service Test 11.51 or earlier, you must expand the REST activity's wrapper and enter these properties in the HTTP Request step found inside the REST activity wrapper.

In the Properties pane's Input/Checkpoints tab , set the destination URL and the HTTP method, usually POST or PUT.

Back to top

Load the request body

  1. In the Properties pane, open the HTTP tab .

  2. Select Body type JSON.

  3. Click the Load JSON button and navigate to the .json file.

    Note: If your JSON file contains non-ASCII characters, you should save this file with UFT-8 encoding. Otherwise, the characters in your file may not display correctly in UFT.

Back to top

Add a request header - optional

Note: If you are working with an API test created in UFT 11.51 or earlier or Service Test 11.51 or earlier, you must expand the REST activity's wrapper and enter these properties in the HTTP Request step found inside the REST activity wrapper.

If your server requires you to specify JSON during content negotiation, you need to set the request header.

  1. In the Properties pane, open the Input/Checkpoints tab .

  2. In the Input/Checkpoints tab, click the plus sign to add a RequestHeader array element.

  3. Add a custom request header named Accept with the value application/json.

Back to top

Modify the JSON body - optional

If you intend to dynamically assign values to the JSON body from a data source, you need to add escape characters.

In the Input/Checkpoints tab, in the Input area, display the Text view of the JSON body and add the escape character, \, for each occurrence of a square or curly bracket ({, }, [, and ]). Do not use an escape character for link expressions enclosed by curly brackets. For example:

\{"results":  
\[
\{"name": "John", "id": 873829904, location: "NY"\},
\{"name": "Linda", "id": 726371109, location: "LA"\},
\{"name": "Mike", "id": 711029345, location: "NY"\},
\]  
\}

When no links are used, this is not required.

Back to top