Skip to content
CheckcraftDownload
Practical workflow

Validate API status codes, headers and response time

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →

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

Checkcraft ·

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.

API call diagram: method and URL, headers, body, status and response body, logs and database

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.

Layers of an API call check: status, headers, body, calculations, logs, database
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 caseExpected codeAlso check
GET an existing object200Body with data
GET a missing object404Error body in JSON, not HTML
POST create201Location header or id in the body
POST, processed later202How to learn the result: a status link
PUT or PATCH200 or 204204 has no body
DELETE204 or 200A follow-up GET returns 404
Too many requests429Retry-After header

Which response headers to check

HeaderWhat to checkWhy it matters
Content-Typeapplication/json; charset=utf-8Otherwise the client cannot parse the body or garbles text
Cache-Controlno-store for personal dataPrivate data must not end up in a cache
LocationAddress of the created object on 201The client knows where to go next
Access-Control-Allow-OriginOnly allowed domainsAn asterisk with cookies opens the API to every site
Strict-Transport-SecurityPresent on HTTPSThe browser will not fall back to HTTP
X-Content-Type-OptionsnosniffThe browser does not guess content type
Retry-AfterPresent on 429 and 503The client knows when to retry
Server, X-Powered-ByNo software versionsVersions help an attacker

CORS headers are checked separately, see CORS error.

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
StageMeaningIf slow
dnsName lookupDNS issue or first request without cache
connectTCP connectionDistant server or congested network
tlsHTTPS handshakeConnections are not reused
first byteWaiting for the first response byteSlow server: database, external calls
totalThe whole requestMuch 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.
  • 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.

Frequently asked questions

Which API response headers should I check?

Content-Type, Cache-Control for personal data, Location on 201, CORS headers, Strict-Transport-Security and Retry-After on 429 and 503.

How do I measure API response time by stage?

curl with -w and the variables time_namelookup, time_connect, time_appconnect, time_starttransfer and time_total.

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 FreeDownload and first run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

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.

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

No account required. We will reply by email. This is a support request, not a newsletter subscription.