DocumentationGrafana k6JavaScript APIjslibhttpxasyncRequest(method, url, [body], [params])
Open source

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

Generic method for making arbitrary asynchronous HTTP requests. Note, this method returns a Promise. You must use the await keyword to resolve it.

methodstringHTTP method. Must be uppercase (GET, POST, PUT, PATCH, OPTIONS, HEAD, etc)
urlstringHTTP URL. If baseURL is set, provide only path.
body (optional)null / string / object / ArrayBuffer / SharedArrayRequest body; objects will be x-www-form-urlencoded. Set to null to omit the body.
params (optional)null or object {}Additional parameters for this specific request.


Promise with ResponseHTTP Response object.


import { Httpx } from '';

const session = new Httpx({
  baseURL: '',
  timeout: 20000, // 20s timeout.

export default async function testSuite() {
  const resp_get = await session.asyncRequest('GET', `/status/200`);
  const resp_post = await session.asyncRequest('POST', `/status/200`, { key: 'value' });
  const resp_put = await session.asyncRequest('PUT', `/status/200`, { key: 'value' });
  const resp_patch = await session.asyncRequest('PATCH', `/status/200`, { key: 'value' });
  const resp_delete = await session.asyncRequest('DELETE', `/status/200`);

  // specific methods are also available.
  const respGet = await session.asyncGet(`/status/200`);
  const respPost = await session.asyncPost(`/status/200`, { key: 'value' });
  const respPut = await session.asyncPut(`/status/200`, { key: 'value' });
  const respPatch = await session.asyncPatch(`/status/200`, { key: 'value' });
  const respDelete = await session.asyncDelete(`/status/200`);