Skip to main content
HTTP requests are the foundation of most k6 load tests. The k6/http module provides methods for all standard HTTP operations.

Making HTTP requests

The simplest HTTP request is a GET request:

POST request with payload

Here’s a more complex example showing a POST request with JSON payload:

Available HTTP methods

The k6/http module supports all standard HTTP methods:

Batch requests

Use http.batch() to send multiple requests in parallel, similar to how browsers load resources:

HTTP request parameters

The third parameter to HTTP methods accepts an object with request configuration:

Following redirects

By default, k6 automatically follows redirects. You can customize this behavior:
Set maxRedirects in options to configure redirect behavior for all requests:

HTTP request tags

k6 automatically tags HTTP requests with metadata for filtering and analysis:

Example tagged output

Here’s how k6 stores metrics with tags:

URL grouping

When testing dynamic URLs, you’ll want to group them to prevent metrics fragmentation.

The problem: dynamic URLs

This code creates 100 different metrics, one for each unique URL:
This makes analysis difficult and consumes more memory.

Solution 1: Custom name tag

Set a custom name tag to group dynamic URLs:
Now all 100 requests are aggregated into a single metric.

Solution 2: http.url template

Use the http.url template literal wrapper:
This automatically groups URLs by replacing variable parts with ${}.

Response object

HTTP methods return a Response object with request/response details:

Useful response properties

res.status

HTTP status code (200, 404, etc.)

res.body

Response body as string

res.json()

Parse response body as JSON

res.timings

Detailed timing breakdown

res.headers

Response headers

res.cookies

Response cookies

Complete example

Here’s a comprehensive example combining multiple concepts:

Best practices

Group dynamic URLs

Use name tags or http.url to prevent metric fragmentation with dynamic URLs.

Use meaningful names

Tag requests with descriptive names for easier analysis.

Check responses

Always validate critical responses with checks.

Batch when possible

Use http.batch() to simulate realistic browser behavior.