> ## 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.

# Basic Load Test

> Learn how to create a simple load test with k6

## Simple GET Request

The most basic k6 test makes a single HTTP GET request:

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

export default function () {
  http.get('https://quickpizza.grafana.com');
};
```

## Load Test with Stages

Use stages (ramping) to control the number of virtual users over time:

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

/*
 * Stages (aka ramping) is how you, in code, specify the ramping of VUs.
 * That is, how many VUs should be active and generating traffic against
 * the target system at any specific point in time for the duration of
 * the test.
 * 
 * The following stages configuration will result in up-flat-down ramping
 * profile over a 20s total test duration.
 */ 

export let options = {
    stages: [
        // Ramp-up from 1 to 5 VUs in 10s
        { duration: "10s", target: 5 },

        // Stay at rest on 5 VUs for 5s
        { duration: "5s", target: 5 },

        // Ramp-down from 5 to 0 VUs for 5s
        { duration: "5s", target: 0 }
    ]
};

export default function() {
    let res = http.get("http://httpbin.org/");
    check(res, { "status is 200": (r) => r.status === 200 });
}
```

<Note>
  The stages configuration creates a realistic load pattern: ramp up, sustain load, then ramp down.
</Note>

## HTTP Methods

k6 supports all standard HTTP methods:

<CodeGroup>
  ```javascript GET theme={null}
  import http from "k6/http";
  import { check } from "k6";

  let res = http.get("http://httpbin.org/get?verb=get");
  check(res, {
      "status is 200": (r) => r.status === 200,
      "is verb correct": (r) => r.json().args.verb === "get",
  });
  ```

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

  let res = http.post("http://httpbin.org/post", { verb: "post" });
  check(res, {
      "status is 200": (r) => r.status === 200,
      "is verb correct": (r) => r.json().form.verb === "post",
  });
  ```

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

  let res = http.put(
    "http://httpbin.org/put", 
    JSON.stringify({ verb: "put" }), 
    { headers: { "Content-Type": "application/json" }}
  );
  check(res, {
      "status is 200": (r) => r.status === 200,
      "is verb correct": (r) => r.json().json.verb === "put",
  });
  ```

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

  let res = http.del("http://httpbin.org/delete?verb=delete");
  check(res, {
      "status is 200": (r) => r.status === 200,
      "is verb correct": (r) => r.json().args.verb === "delete",
  });
  ```
</CodeGroup>

## Working with JSON

Sending and parsing JSON data:

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

export default function() {
    // Send a JSON encoded POST request
    let body = JSON.stringify({ key: "value" });
    let res = http.post(
      "http://httpbin.org/post", 
      body, 
      { headers: { "Content-Type": "application/json" }}
    );

    // Use JSON.parse to deserialize the JSON (instead of using the r.json() method)
    let j = JSON.parse(res.body);

    // Verify response
    check(res, {
        "status is 200": (r) => r.status === 200,
        "is key correct": (r) => j.json.key === "value",
    });
}
```
