Skip to content

RestAPI

Communicates with HTTP and HTTPS, with built-in support for Azure authenticated endpoints.

Request methods

Supports the following request methods:

  • get
  • put
  • post

Format

Format of host is the following:

Examples

Example on how to use it in a scenario:

To change how often the token should be refreshed, default is 3000 seconds:

Authentication

See Azure Active Directory.

It is possible to change authenticated user during runtime by using step_setup_set_context_variable step expressions inbetween other tasks. To change user both auth.user.username and auth.user.password has to be changed (even though maybe only one of them changes value).

This will then cache the Authorization token for the current user, and if changed back to that user there is no need to re-authenticate again, unless refresh_time for the first login expires.

In the above, hypotetical scenario, there will 2 "AAD OAuth2 user token" requests, once for user "bob" and one for user "alice", both done in the first iteration. The second iteration the cached authentication tokens will be re-used.

Multipart/form-data

RestApi supports posting of multipart/form-data content-type, and in that case additional arguments needs to be passed with the request:

  • multipart_form_data_name str - the name of the input form

  • multipart_form_data_filename str - the filename

http[s]://<hostname>
Given a user of type "RestApi" load testing "https://api.example.com"
Then post request "test/request.j2.json" to endpoint "/api/test"
Then get request from endpoint "/api/test"
And set context variable "auth.refresh_time" to "3500"
Given a user of type "RestApi" load testing "https://api.example.com"
And repeat for "2" iterations
And set context variable "user.auth.username" to "bob"
And set context variable "user.auth.password" to "foobar"

Then get request from endpoint "/api/test"

Given set context variable "user.auth.username" to "alice"
And set context variable "user.auth.password" to "hello world"

Then get request from endpoint "/api/test"

Given set context variable "user.auth.username" to "bob"
And set context variable "user.auth.password" to "foobar"

Example:

Then post request "path/my_template.j2.xml" with name "FormPost" to endpoint "example.url.com | content_type=multipart/form-data, multipart_form_data_filename=my_filename, multipart_form_data_name=form_name"