When you create a new load test, you'll often first define the HTTP requests that you will use to test your system.
A simple GET request looks like this:
For something slightly more complex, here's a POST request to authenticate on a service or site:
The http module handles all kinds of HTTP requests and methods.
|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.|
|head()||Issue an HTTP HEAD 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 automatically applies tags to your HTTP requests. These tags let you filter your results, helping you organize your analysis.
|expected_response||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|
The following snippet shows a JSON example of how a test-result data point is logged. In this example, the metric is the duration of an HTTP request.
Note how the tags object groups data.
By default, tags have a name field that holds the value of the request URL. If your test has dynamic URL paths, you might not want this behavior, which could bring a large number of unique URLs into the metrics stream. For example, the following code accesses 100 different URLs:
You might prefer to report this data in a single metric: To aggregate data from dynamic URLs, explicitly set a name tag:
That code would produce JSON output like this:
Note how these two objects have the same name, despite having different URLs. If you filter the results for the tag name: PostsItemURL, the results include all data points from all 100 URLs.
As an alternative, you can also use the http.url wrapper to set the name tag with a string template value:
k6 Cloud Results HTTP Table organizes requests by URL.