Create a REST service model

Relevant for: API testing only

This topic describes how to create a REST service model.

Prerequisite

Study the structure of the REST Service body and determine which resources and methods you need to define.

Back to top

Create the service model hierarchy

In order for UFT One to create and use the service model, you must define the hierarchy of the service, including its resources and methods:

  1. In the toolbar, click the Add REST Service drop-down button and select REST Service Editor.

  2. In the Add REST Service editor, give the service a name.

  3. Add resources and methods as needed:

    For new resources

    Click the Add Resource toolbar button and provide a meaningful name for the resource.

    For new methods

    Click the Add Method toolbar button and provide a meaningful name for the method.

Back to top

Set the General properties

  1. Select the service, resource or method for which you want to set its properties.

  2. In the right pane's Properties list, open the General tab.

  3. Enter values for the properties.

Back to top

Set the URL property values

  1. In the REST Service editor, select a REST service, resource, or method.

  2. In the General tab, enter the URL property value:

    • If you are entering a URL property value for a REST service, enter the URL prefix in the URL property row, beginning with a http://

    • If you are entering a URL property value for a REST resource or method, enter the URL property value in the Relative URL property row.

    Note: If you enter a URL property value for the service or resource of your REST service, the URL property values are passed to all resources or methods included in the service or resource. For details, see Pass REST service properties

Back to top

Define the method's HTTP properties

  1. Select a REST service method.

  2. In the REST service editor's right pane, click the HTTP Input/Checkpoints tab .

  3. For each method, modify the HTTP method and HTTP version.

  4. Use the plus sign in the RequestHeaders parent node to add name and value pairs for the request header array.

Back to top

Define custom properties - optional

For methods that require input, such as PUT or POST, you can add custom input properties. For methods that provide an output such as GET, you add the required output properties. To create these properties:

  1. In the right pane's Properties list, click the Custom Input/Checkpoints tab .

  2. Expand the plus button and select Add Input/Output Property.

  3. Provide a name, data type, and description (optional) for each property.

  4. Enter the property values in the Value column.

Back to top

Enter the request body directly - optional

This section describes how to enter the request body directly.

  1. Return to the design document for the REST service and copy the Request body onto the clipboard.

  2. In the right pane of the Add REST Service window, open the HTTP tab .

    Make sure the Request Body type in the drop down is set to Text, and click within the Body section.

    Press CTRL+V to paste the contents of the request into the pane. Make sure that there are no extra spaces before or after the body text.

  3. Modify the element values within the XML body as required.

    UFT One versions 2021 R1 and later: To insert an encrypted password into your request body or encrypt a plaintext password included in your request body, do the following:

    1. In the Text editor, put your cursor where you want to insert or highlight the password you want to encrypt, and then click Password. Alternatively, you can just click the corresponding input box in the Grid view, and then click Password.

    2. In the Input Password dialog box that opens, enter your plaintext password. UFT One automatically encrypts the password and inserts it into your request body.

Note: If you need to use a multipart request with your REST Service methods, this is done after dragging the REST method to the canvas, For details, see Send a multipart HTTP or REST Service request.

Back to top

Link the body request to a data source - optional

This section describes how to enter the Request body through a data source.

  1. Return to the design document for the REST service and copy the request body to the clipboard.

  2. In the right pane of the Add REST Service dialog box, open the HTTP tab . Make sure the Request Body type in the drop down is set to Text, and click within the Body section.

  3. Click the Link Body button to the right of the pane, to open the Select Link Source dialog box.

  4. In the Select Link Source dialog box, click Custom Expression to expand the dialog box. Paste the clipboard contents, the Request body, into the Expression area.

  5. In the Expression area, highlight the value of the element you want to link. In the upper pane, double-click on the custom property you defined earlier in the properties list. The property is now linked to a value.

    The modified expression appears in the Expression area. In the following example the custom Class property is linked to Class element in the REST document.

    <Class>{Step.InputProperties.RestMethod.Class}</Class>
  6. Click OK. UFT One places the data in the Body section.

  7. UFT One versions 2021 R1 and later: To insert an encrypted password into your request body or encrypt a plaintext password included in your request body, do the following:

    1. In the Text editor, put your cursor where you want to insert or highlight the password you want to encrypt, and then click Password. Alternatively, you can just click the corresponding input box in the Grid view, and then click Password.

    2. In the Input Password dialog box that opens, enter your plaintext password. UFT One automatically encrypts the password and inserts it into your request body.

Note: If you need to use a multipart request with your REST Service methods, this is done after dragging the REST method to the canvas, For details, see Send a multipart HTTP or REST Service request.

Back to top

Test the method

Click the Run Method button on the toolbar to test the method with its property values. The results are displayed in the lower section of the window.

Back to top

Save the service model to your test

In the REST Service editor, click OK in the Design REST Service dialog box. UFT One adds the REST service along with its resources and methods to the Toolbox pane, under the Local Activities category.

Back to top

Expose input and output properties

You can forward built-in HTTP properties to the REST method wrapper. This is useful for making specific HTTP properties available at the wrapper level.

Note: If you created a REST method in UFT One 11.52 or Service Test 11.52 or later, all REST Service method properties are incorporated into the REST activity step itself without a wrapper.

  1. Double-click a REST method from the Toolbox pane to add it to the canvas. Expand the method to show the HTTP Request frame.

  2. Click in the HTTP Request frame. Select a property in the Properties pane and select Expose as Input Property or Expose as Output Property from the right-click menu.

  3. Provide a name for the property in the New Exposed Property dialog box.

  4. Click the REST method wrapper in the canvas, and view the newly exposed property in the Properties pane's Custom Input/Checkpoints tab .

Back to top

See also: