# Validate API status codes, headers and response time

Source: https://checkcraft.ru/en/guides/http-response-checks.html · updated 2026-11-24

Check HTTP status codes, Content-Type, JSON body fields and response time as independent assertions in Checkcraft.

Practical workflow

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. [Download, no sign-up →](https://checkcraft.ru/en/download-checkcraft.html#free-download)

A visible response is not yet a repeatable test. Status, headers and content can fail independently.

Checkcraft · 10 October 2026

Get help with your first test →

## Prepare an HTTP run

Create a request to a test API or mock and select its test cases. Status and headers come from response metadata. A JSON document pasted for analysis does not include that metadata.

## Assert the status

Use the HTTP status assertion with the contract value. Reading a resource may return 200 while creating one may require 201. Treat all 2xx values as equivalent only when the contract allows it.

Repeating checks like this by hand? Checkcraft saves them and reruns them in one click. [Download Free →](https://checkcraft.ru/en/download-checkcraft.html#free-download)

## Assert headers and content

Use the response header assertion for Content-Type, accounting for permitted charset parameters. Use the JSON response field assertion for a business value. Frontend and backend contracts may distinguish the string "2" from the number 2.

## Set a time threshold

A response time assertion compares milliseconds against your limit. The 1000 ms example is not a universal SLA. Network and environment affect duration. A single request cannot establish throughput or load behavior.

```
expected status = 200
Content-Type contains application/json
response time <= 1000 ms
```

## Check browser-specific behavior

Desktop success does not prove that a browser will allow the same call under CORS. Inspect browser console errors, cookies and the environment separately. This helps distinguish API behavior from frontend restrictions.

## Which code to expect for each method

| Method and case | Expected code | Also check |
|---|---|---|
| GET an existing object | 200 | Body with data |
| GET a missing object | 404 | Error body in JSON, not HTML |
| POST create | 201 | Location header or id in the body |
| POST, processed later | 202 | How to learn the result: a status link |
| PUT or PATCH | 200 or 204 | 204 has no body |
| DELETE | 204 or 200 | A follow-up GET returns 404 |
| Too many requests | 429 | Retry-After header |

## Which response headers to check

| Header | What to check | Why it matters |
|---|---|---|
| Content-Type | application/json; charset=utf-8 | Otherwise the client cannot parse the body or garbles text |
| Cache-Control | no-store for personal data | Private data must not end up in a cache |
| Location | Address of the created object on 201 | The client knows where to go next |
| Access-Control-Allow-Origin | Only allowed domains | An asterisk with cookies opens the API to every site |
| Strict-Transport-Security | Present on HTTPS | The browser will not fall back to HTTP |
| X-Content-Type-Options | nosniff | The browser does not guess content type |
| Retry-After | Present on 429 and 503 | The client knows when to retry |
| Server, X-Powered-By | No software versions | Versions help an attacker |

CORS headers are checked separately, see [CORS error](https://checkcraft.ru/en/guides/cors-error.html).

## What response time is made of

```
curl -s -o /dev/null -w "dns %{time_namelookup}\nconnect %{time_connect}\ntls %{time_appconnect}\nfirst byte %{time_starttransfer}\ntotal %{time_total}\n" https://api.example.com/orders/5001
```
| Stage | Meaning | If slow |
|---|---|---|
| dns | Name lookup | DNS issue or first request without cache |
| connect | TCP connection | Distant server or congested network |
| tls | HTTPS handshake | Connections are not reused |
| first byte | Waiting for the first response byte | Slow server: database, external calls |
| total | The whole request | Much larger than first byte means a big response |

curl time is measured from your machine. In tests compare with the threshold from requirements and account for the network to the stand.

## How to set a time threshold

- Use the requirement if there is one: for example, 95% of requests under 500 ms.
- Without one, measure 20–30 runs on the stand and set a threshold with headroom above the usual value.
- One slow run is not a defect. Treat a steady excess as one.
- The first request after idle may be slower due to warm-up; you can ignore it.
- Load testing needs other tools such as k6 or JMeter. A functional time check only catches obvious degradation.

## The same checks in Postman and pytest

### Postman

```
pm.test("status and headers", () => {
  pm.response.to.have.status(200);
  pm.expect(pm.response.headers.get("Content-Type")).to.include("application/json");
  pm.expect(pm.response.headers.get("Cache-Control")).to.include("no-store");
});
pm.test("under 800 ms", () => pm.expect(pm.response.responseTime).to.be.below(800));
```

### Python, pytest

```
r = requests.get(URL, headers=AUTH, timeout=10)
assert r.status_code == 200
assert r.headers["Content-Type"].startswith("application/json")
assert "no-store" in r.headers.get("Cache-Control", "")
assert r.elapsed.total_seconds() < 0.8
```

## Cache: ETag and 304

If the server sends an ETag, the client can ask "has anything changed" and get an empty 304 instead of the whole body.

```
curl -si https://api.example.com/catalog | grep -i etag
# ETag: "a1b2c3"
curl -si -H 'If-None-Match: "a1b2c3"' https://api.example.com/catalog | head -1
# HTTP/1.1 304 Not Modified
```

Check both cases: unchanged gives 304, after a data change 200 with a new ETag. Personal data is usually excluded from caching with Cache-Control: no-store.

## Compression and response size

Large responses should be compressed. The client says what it supports with Accept-Encoding, the server answers Content-Encoding: gzip or br. curl --compressed requests and unpacks a compressed response.

```
curl -s -o /dev/null -w "%{size_download} bytes\n" https://api.example.com/catalog
curl -s --compressed -o /dev/null -w "%{size_download} bytes\n" https://api.example.com/catalog
```

If the second number is not smaller, compression is off. For lists of hundreds of kilobytes this noticeably slows mobile clients.

## Common findings

- A 404 comes as an HTML page with text/html and the client fails to parse it, see [DOCTYPE is not valid JSON](https://checkcraft.ru/en/guides/json-doctype-not-valid.html).
- A user profile is cached by a proxy because Cache-Control is missing.
- POST creates an object and answers 200 without Location or id.
- The Server header shows the exact nginx or framework version.
- Response time grows with database size: fast on an empty stand, slow on a production-size copy.

Next step

## Repeat this on your own API

Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.

[Download Free](https://checkcraft.ru/en/download-checkcraft.html#free-download) · [Download and first run](https://checkcraft.ru/en/download-checkcraft.html)

No sign-up or email needed, the archive is ready in a couple of minutes. See the [edition limits](https://checkcraft.ru/en/pricing.html).

## Continue with a related task

[Configure API request authentication](https://checkcraft.ru/en/guides/api-request-authorization.html) · [Create a local API mock server](https://checkcraft.ru/en/guides/local-api-mock.html)

Start with the linked example and compare its result with your own test requirement.

Ask a person

## Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

[Ask in Telegram](https://t.me/checkcraftchat)Send an email

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

Page card: /ai/pages/en/guides/http-response-checks.md
