No results for

Powered byAlgolia
⚠️ This documentation is outdated. Please visit for the latest k6 documentation.📚

asyncRequest( method, url, [body], [params] )

methodstringRequest method (e.g. 'POST'). Must be uppercase.
urlstring / HTTP URLRequest URL (e.g. '').
body (optional)string / object / ArrayBufferRequest body. Objects will be x-www-form-urlencoded encoded.
params (optional)objectParams object containing additional request parameters.


Promise with ResponseHTTP Response object.


Using http.asyncRequest() to issue a POST request:

import http from 'k6/http';
const url = '';
export default async function () {
const data = { name: 'Bert' };
// Using a JSON string as body
let res = await http.asyncRequest('POST', url, JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' },
console.log(res.json(); // Bert
// Using an object as body, the headers will automatically include
// 'Content-Type: application/x-www-form-urlencoded'.
res = await http.asyncRequest('POST', url, data);
console.log(res.json(); // Bert

Using http.asyncRequest() to issue multiple requests, then Promise.race to determine which requests finish first:

import http from 'k6/http';
export default async () => {
const urlOne = `${randomInt(1, 5)}`
const urlTwo = `${randomInt(1, 5)}`
const urlThree = `${randomInt(1, 5)}`
const one = http.asyncRequest('GET', urlOne);
const two = http.asyncRequest('GET', urlTwo);
const three = http.asyncRequest('GET', urlThree);
const res = await Promise.race([one, two, three])
console.log('winner is', res.url, 'with duration of', res.timings.duration+'ms');
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min) + min);