> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/grafana/k6/llms.txt
> Use this file to discover all available pages before exploring further.

# k6/http

> HTTP client module for making HTTP requests and handling responses.

The `k6/http` module provides functionality for making HTTP requests.

## Functions

### get(url, \[params])

Makes an HTTP GET request.

<ParamField path="url" type="string">
  Target URL
</ParamField>

<ParamField path="params" type="object" optional>
  Request parameters (headers, tags, etc.)
</ParamField>

<ResponseField name="response" type="Response">
  HTTP response object
</ResponseField>

```javascript theme={null}
import http from 'k6/http';

export default function () {
  const res = http.get('https://test.k6.io');
  console.log(res.status);
}
```

### post(url, \[body], \[params])

Makes an HTTP POST request.

<ParamField path="url" type="string">
  Target URL
</ParamField>

<ParamField path="body" type="string | object | ArrayBuffer" optional>
  Request body
</ParamField>

<ParamField path="params" type="object" optional>
  Request parameters
</ParamField>

```javascript theme={null}
import http from 'k6/http';

export default function () {
  const payload = JSON.stringify({ name: 'test' });
  const params = {
    headers: { 'Content-Type': 'application/json' },
  };
  http.post('https://test.k6.io/api', payload, params);
}
```

### put(url, \[body], \[params])

Makes an HTTP PUT request.

<ParamField path="url" type="string">
  Target URL
</ParamField>

<ParamField path="body" type="string | object | ArrayBuffer" optional>
  Request body
</ParamField>

<ParamField path="params" type="object" optional>
  Request parameters
</ParamField>

### patch(url, \[body], \[params])

Makes an HTTP PATCH request.

### del(url, \[body], \[params])

Makes an HTTP DELETE request.

### head(url, \[params])

Makes an HTTP HEAD request.

### options(url, \[body], \[params])

Makes an HTTP OPTIONS request.

### request(method, url, \[body], \[params])

Makes an HTTP request with the specified method.

<ParamField path="method" type="string">
  HTTP method (GET, POST, etc.)
</ParamField>

<ParamField path="url" type="string">
  Target URL
</ParamField>

<ParamField path="body" type="string | object | ArrayBuffer" optional>
  Request body
</ParamField>

<ParamField path="params" type="object" optional>
  Request parameters
</ParamField>

### batch(requests)

Makes multiple HTTP requests in parallel.

<ParamField path="requests" type="array | object">
  Array or object containing request definitions
</ParamField>

```javascript theme={null}
import http from 'k6/http';

export default function () {
  const responses = http.batch([
    ['GET', 'https://test.k6.io'],
    ['GET', 'https://test.k6.io/contacts'],
  ]);
  console.log(responses[0].status);
}
```

### file(data, \[filename], \[contentType])

Creates a file object for multipart requests.

<ParamField path="data" type="string | ArrayBuffer">
  File content
</ParamField>

<ParamField path="filename" type="string" optional>
  Filename
</ParamField>

<ParamField path="contentType" type="string" optional>
  Content type
</ParamField>

## Classes

### CookieJar

Manages HTTP cookies.

```javascript theme={null}
import http from 'k6/http';

const jar = http.cookieJar();
jar.set('https://test.k6.io', 'session_id', '12345');
```

## Response Object

HTTP response objects contain:

<ResponseField name="status" type="number">
  HTTP status code
</ResponseField>

<ResponseField name="body" type="string">
  Response body as string
</ResponseField>

<ResponseField name="headers" type="object">
  Response headers
</ResponseField>

<ResponseField name="timings" type="object">
  Response timing information
</ResponseField>

<ResponseField name="json()" type="function">
  Parse response body as JSON
</ResponseField>

## Constants

### TLS Versions

* `http.TLS_1_0`
* `http.TLS_1_1`
* `http.TLS_1_2`
* `http.TLS_1_3`

### OCSP Status

* `http.OCSP_STATUS_GOOD`
* `http.OCSP_STATUS_REVOKED`
* `http.OCSP_STATUS_UNKNOWN`
* `http.OCSP_STATUS_SERVER_FAILED`

## Examples

### Complete Example

```javascript theme={null}
import http from 'k6/http';
import { check } from 'k6';

export default function () {
  const res = http.get('https://quickpizza.grafana.com');
  
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 500ms': (r) => r.timings.duration < 500,
  });
}
```

### POST with JSON

```javascript theme={null}
import http from 'k6/http';

export default function () {
  const url = 'https://httpbin.org/post';
  const payload = JSON.stringify({
    name: 'k6 test',
  });

  const params = {
    headers: {
      'Content-Type': 'application/json',
    },
  };

  http.post(url, payload, params);
}
```
