When creating a new load test, the first thing you'll often do is define the HTTP requests that will be used to test your system. A simple example that just performs a GET request looks like this:
A slightly more complex request might be e.g. a POST request to authenticate on a site/service:
Use the http module to perform all kinds of HTTP requests in your load tests.
|batch()||Issue multiple HTTP requests in parallel (like e.g. browsers tend to do).|
|del()||Issue an HTTP DELETE request.|
|get()||Issue an HTTP GET request.|
|options()||Issue an HTTP OPTIONS request.|
|patch()||Issue an HTTP PATCH request.|
|post()||Issue an HTTP POST request.|
|put()||Issue an HTTP PUT request.|
|request()||Issue any type of HTTP request.|
k6 will automatically apply tags to your HTTP requests. These tags allow you to filter your results during analysis.
|expected_response (≥ v0.31)||By default, response statuses between 200 and 399 are true. Change the default behavior with setResponseCallback.|
|group||When the request runs inside a group, the tag value is the group name. Default is empty.|
|name||Defaults to URL requested|
|method||Request method (GET, POST, PUT etc.)|
|scenario||When the request runs inside a scenario, the tag value is the scenario name. Default is default.|
|url||defaults to URL requested|
Below you can see how a test result data point (the duration of an HTTP request) is logged, in JSON format, including the various tags mentioned above:
By default, requests report the name tag with the value of the request URL. For URLs that contain dynamic parts, this might not be desirable since it can introduce a large number of unique URLs in the metrics stream. The below code shows a situation when you'll access 100 different URLs but may want them all reported using one single metric:
You can aggregate data from dynamic URLs by explicitly setting a name tag:
Which would produce JSON output like the following:
Note how the name is the same for the two data samples related to two different URLs. Filtering the results on tag name: PostsItemURL will give you a result set including all the data points from all the 100 different URLs.
Additionally, you can use the http.url wrapper to set the name tag with a string template value:
k6 Cloud Results's HTTP Table will show all the requests, on an aggregated level per URL.