Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-http/request.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-http/request/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
request( method, url, [body], [params] )
| Parameter | Type | Description |
|---|---|---|
| method | string | Request method (e.g. 'POST'). Must be uppercase. |
| url | string / HTTP URL | Request URL (e.g. 'http://example.com'). |
| body (optional) | string / object / ArrayBuffer | Request body; Objects will be x-www-form-urlencoded encoded. |
| params (optional) | object | Params object containing additional request parameters. |
Form-encoded request bodies
When you pass a JavaScript object as the body without file uploads, k6 encodes it as application/x-www-form-urlencoded:
nullandundefinedbecome empty values, such asname=. The field remains in the request.- Arrays produce repeated keys, such as
tag=one&tag=two. - Nested objects and nested arrays become empty values and cause k6 to log a warning. This also applies to objects inside arrays.
For example, { name: null, tags: ['one', null] } becomes name=&tags=one&tags=.
To preserve nested data, serialize the body with JSON.stringify() and set the Content-Type header to application/json. Setting the header alone does not convert an object body to JSON.
These rules also apply to methods such as post().
Returns
| Type | Description |
|---|---|
| Response | HTTP Response object. |
Example
Using http.request() to issue a POST request:
import http from 'k6/http';
const url = 'https://quickpizza.grafana.com/api/post';
export default function () {
const data = { name: 'Bert' };
// Using a JSON string as body
let res = http.request('POST', url, JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' },
});
console.log(res.json().name); // Bert
// Using an object as body, the headers will automatically include
// 'Content-Type: application/x-www-form-urlencoded'.
res = http.request('POST', url, data);
console.log(res.body); // name=Bert
}Was this page helpful?
Related resources from Grafana Labs

