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).
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!
- Goland 1.20+
- Git
- xk6 (
go install go.k6.io/xk6/cmd/xk6@latest
)
-
Build the k6 binary:
make build
-
Run an example:
./k6 run ./examples/test.js
- 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 examplesSome examples are on todo list but i will deliver them very fast don't wory.
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.
For support, email [email protected] or join my telegram group.