This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.

Documentationbreadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow k6/httpbreadcrumb arrow query( url, [body], [params] )
Open source

query( url, [body], [params] )

http.query() issues an HTTP QUERY request, defined in RFC 10008. QUERY is safe and idempotent like GET, but carries a request body, which makes it a good fit for queries that are too large, complex, or sensitive to put in the URL.

ParameterTypeDescription
urlstring / HTTP URLRequest URL (e.g. http://example.com).
bodystring / object / ArrayBufferRequest body; objects will be x-www-form-urlencoded.
params (optional)objectParams object containing additional request parameters.

For object bodies without file uploads, refer to the form encoding rules.

Returns

TypeDescription
ResponseHTTP Response object.

Example

JavaScript
import http from 'k6/http';

const url = 'https://quickpizza.grafana.com/api/query';

export default function () {
  const headers = { 'Content-Type': 'application/json' };
  const query = { maxPrice: 15, filters: ['vegetarian'] };

  const res = http.query(url, JSON.stringify(query), { headers: headers });

  console.log(JSON.parse(res.body).json);
}