# Response Validation with Checks
## Rule
Every HTTP request in a k6 script MUST have at least one `check()` call validating the response. Requests without checks can return errors that are invisible in metrics.
## Format
```javascript
import { check } from 'k6';
const res = http.get(url);
check(res, {
'status is 200': (r) => r.status === 200,
'response has data': (r) => JSON.parse(r.body).data !== undefined,
});
```
## Required Checks Per Request Type
### GET Requests
```javascript
check(res, {
'status is 200': (r) => r.status === 200,
'response body is not empty': (r) => r.body.length > 0,
'response is valid JSON': (r) => {
try { JSON.parse(r.body); return true; } catch { return false; }
},
});
```
### POST Requests
```javascript
check(res, {
'status is 201': (r) => r.status === 201,
'returns created resource': (r) => JSON.parse(r.body).id !== undefined,
});
```
### Authentication
```javascript
check(loginRes, {
'login returns 200': (r) => r.status === 200,
'returns auth token': (r) => JSON.parse(r.body).token !== undefined,
'token is not empty': (r) => JSON.parse(r.body).token.length > 0,
});
```
## Examples
### Good
```javascript
export default function () {
const res = http.get(BASE_URL + '/api/products');
check(res, {
'products status 200': (r) => r.status === 200,
'products returns array': (r) => Array.isArray(JSON.parse(r.body).data),
'products count > 0': (r) => JSON.parse(r.body).data.length > 0,
});
}
```
### Bad
```javascript
export default function () {
// No checks — server errors are invisible!
http.get(BASE_URL + '/api/products');
sleep(1);
}
```
## Anti-Patterns
- HTTP requests without any check() calls
- Checking only status code without body validation
- Ignoring check failures in threshold configuration
- Parsing response body multiple times (parse once, check multiple fields)