Batch multiple HTTP requests together to issue them in parallel over multiple TCP connections. To set batch size, use the batch per host option.
|requests||array | object||An array or object containing requests, in string or object form|
You have multiple ways to structure batch requests:
- In an array of arrays
- As an object or array of objects
- As an array of URL strings
Defining batch requests as URL strings is a shortcut for GET requests. You can use this GET shortcut in objects—name a key and give it a URL value (refer to subsequent sections for example syntax).
Array and Object
You can define a request specified as an array or object with the following parameters.
When you define requests as an array, you must use a specific order of items. Note the Position column for the correct order.
|1||method||string||Mandatory. The HTTP method of the request. One of GET, POST, PUT, PATCH, DELETE, HEAD or OPTION.|
|2||url||string / HTTP URL||Mandatory. The URL to request.|
|3||body (optional)||string / object / ArrayBuffer||The body of the request if relevant. Can be set to null if not applicable but you want to set the last params argument.|
|4||params (optional)||object||Params like auth, custom headers and tags.|
If you pass an array of string values, k6 automatically parses them into a batch of GET requests, where the target is the value of the strings.
|object||The returned object contains Response objects.|
It is an array when users pass an array as requests, and is an ordinary object with string keys when named requests are used (see below).
This example batches three URLs in arrays for parallel fetching:
This example uses objects to define a batch of POST requests (along with custom HTTP headers in a Params object to the request):
Batch requests can happen in any order, or simultaneusly.
In the preceding example, req1 can happen before req2 or req3.
This example uses an array of URL strings to send a batch of GET requests.
Finally, you can also send in named requests by using an object instead of an array as the parameter to http.batch(). This example mixes string URLs and request objects.