Skip to content

This extension goal is to change the way users used to make HTTP connection with k6. It's an implementation for this design document: https://github.com/grafana/k6/blob/master/docs/design/018-new-http-api.md

Notifications You must be signed in to change notification settings

saniyar-dev/xk6-new-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xk6-new-http

This extension goal is to change the way users used to make HTTP connection with k6.

As you can see in k6 repo there is lots of issues with old/standard HTTP API implemented in k6 originally. So they came with an idea to design a complete new HTTP API (you can see the design document here).

What i'm doing?

I couldn't find an implementation for the design document here, so i decided to implement it myself and contribute to the great k6. I need you to know that this project is a working progress and also my hubby as a side project, so don't expect something unordinary great from it. I hope some day it will be a great implementation of phase 1, but today is not the day. Hope you enjoy it!

Requirements

Getting started

  1. Build the k6 binary: make build

  2. Run an example: ./k6 run ./examples/test.js

Usage/Examples

  • Using a client with default transport settings, and making a GET request:
import { Client } from 'k6/x/net/http';

export default async function () {
  const client = new Client();
  const response = await client.get('https://httpbin.test.k6.io/get');
  const jsonData = await response.json();
  console.log(jsonData);
}

  • Creating a client with custom transport settings, some HTTP options, and making a POST request:

    This example is on todo list and doesn't work now

import { TCP } from 'k6/x/net';
import { Client } from 'k6/x/net/http';

export default async function () {
  const client = new Client({
    dial: async address => {
      return await TCP.open(address, { keepAlive: true });
    },
    proxy: 'https://myproxy',
    headers: { 'User-Agent': 'k6' },  // set some global headers
  });
  await client.post('http://10.0.0.10/post', {
    json: { name: 'k6' }, // automatically adds 'Content-Type: application/json' header
  });
}

  • see examples dir for more examples

    Some examples are on todo list but i will deliver them very fast don't wory.

Contributing

Contributions are always welcome!

You can fork this project, create your branch, work on it, document your work and reasons behind it, contact me on telegram and do a pull request.

Support

For support, email [email protected] or join my telegram group.

🔗 Links

linkedin twitter

About

This extension goal is to change the way users used to make HTTP connection with k6. It's an implementation for this design document: https://github.com/grafana/k6/blob/master/docs/design/018-new-http-api.md

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published