Open source RSS


The httpx module is an external JavaScript library that wraps around the native k6/http module. It’s a http client with features that are not yet available in the native module.

  • ability to set http options globally (such as timeout)
  • ability to set default tags and headers that will be used for all requests
  • more user-friendly arguments to request functions (get, post, put take the same arguments)

httpx module integrates well with the expect library.

The source code is on GitHub. Please request features and report bugs through GitHub issues.


This library is in active development.

This library is stable enough to be useful, but pay attention to the new versions released on

This documentation is for the only last version only. If you discover that some of the following doesn’t work, you might be using an older version.


asyncRequest(method, url, [body], [params])Generic method for making arbitrary, asynchronous HTTP requests.
request(method, url, [body], [params])Generic method for making arbitrary HTTP requests.
get(url, [body], [params])Makes GET request
post(url, [body], [params])Makes POST request
put(url, [body], [params])Makes PUT request
patch(url, [body], [params])Makes PATCH request
delete(url, [body], [params])Makes DELETE request
batch(requests)Batches multiple HTTP requests together to issue them in parallel.
setBaseUrl(url)Sets the base URL for the session
addHeader(key, value)Adds a header to the session
addHeaders(object)Adds multiple headers to the session
clearHeader(name)Removes header from the session
addTag(key, value)Adds a tag to the session
addTags(object)Adds multiple tags to the session
clearTag(name)Removes tag from the session


import { fail } from 'k6';
import { Httpx } from '';
import { randomIntBetween } from '';

const USERNAME = `user${randomIntBetween(1, 100000)}`; // random email address
const PASSWORD = 'superCroc2021';

const session = new Httpx({
  baseURL: '',
  headers: {
    'User-Agent': 'My custom user agent',
    'Content-Type': 'application/x-www-form-urlencoded',
  timeout: 20000, // 20s timeout.

export default function testSuite() {
  const registrationResp =`/user/register/`, {
    first_name: 'Crocodile',
    last_name: 'Owner',
    username: USERNAME,
    password: PASSWORD,

  if (registrationResp.status !== 201) {
    fail('registration failed');

  const loginResp =`/auth/token/login/`, {
    username: USERNAME,
    password: PASSWORD,

  if (loginResp.status !== 200) {
    fail('Authentication failed');

  const authToken = loginResp.json('access');

  // set the authorization header on the session for the subsequent requests.
  session.addHeader('Authorization', `Bearer ${authToken}`);

  const payload = {
    name: `Croc Name`,
    sex: 'M',
    date_of_birth: '2019-01-01',

  // this request uses the Authorization header set above.
  const respCreateCrocodile =`/my/crocodiles/`, payload);

  if (respCreateCrocodile.status !== 201) {
    fail('Crocodile creation failed');
  } else {
    console.log('New crocodile created');