Post Request using k6

As we learned in our first tutorial about what is k6 and why do we need to use k6 for load testing purpose. If you have not read my article on it yet please read before you read this article.

What is k6?

How to make post request using k6?

Sometimes you want to load test post endpoint where you need to send some payload along with some custom headers.

In this tutorial I will show you how to pass custom headers and payload to post request using k6. Following code will test the login page with some payload and custom headers.

import http from 'k6/http';

export default function () {

  // send custom payload/post data
  const payload = JSON.stringify({
    email: 'aaa',
    password: 'bbb',

 // send post request with custom header and payload'', payload, {
    headers: {
      'Content-Type': 'application/json',

Now, run above script to see the results on your terminal:

k6 run test.js