Skip to main content

API Testing Quick Reference

A lookup page for exploring and testing HTTP APIs: status codes, curl flags, auth headers, checklists, and the same request in several tools.

How to use this page

This page is for looking things up, not for learning from scratch. New to APIs? Start with the API testing cheat sheet, which explains each idea with an exercise. For the ordered plan with projects, see the API testing learning path.

Quick Navigation​

HTTP: Methods Β· Status codes Β· Headers Β· Auth

Tools: curl Β· Postman scripts Β· Newman Β· Same request, five tools Β· GraphQL

Testing: Endpoint checklist Β· Negative test ideas Β· Security checks Β· Bug report for an API

Recipes: One-liners


Methods​

MethodPurposeBody?Idempotent?Typical success
GETReadNoYes200
HEADHeaders onlyNoYes200
POSTCreate / actionYesNo201 (or 200)
PUTReplaceYesYes200 / 204
PATCHPartial updateYesNot guaranteed200 / 204
DELETERemoveUsually noYes204 / 200
OPTIONSWhich methods are allowed (CORS preflight)NoYes204 / 200

Status codes​

CodeNameTest that you get it when…
200OKA read or update succeeds
201CreatedA create succeeds (check Location header)
204No ContentSuccess with no body
301 / 302 / 307 / 308RedirectsOld URLs move; method kept on 307/308
304Not ModifiedCaching with If-None-Match / ETag
400Bad RequestMalformed or invalid input
401UnauthorizedNo / invalid credentials
403ForbiddenValid user, not allowed
404Not FoundUnknown id or path
405Method Not AllowedWrong method on a path
409ConflictDuplicate or state clash
413Payload Too LargeUpload over the limit
415Unsupported Media TypeWrong Content-Type
422Unprocessable ContentValid JSON, invalid meaning
429Too Many RequestsRate limit (check Retry-After)
500Internal Server ErrorNever on purpose β€” always a bug
502 / 503 / 504Gateway / unavailable / timeoutDependency or infrastructure trouble

Headers​

HeaderExample
Content-Typeapplication/json, multipart/form-data, application/x-www-form-urlencoded
Acceptapplication/json
AuthorizationBasic dXNlcjpwYXNz, Bearer eyJhbGciOi…
Cookietoken=abc123
x-api-key<YOUR_KEY>
Idempotency-Key8e3f… (unique per logical operation)
If-None-Match / ETagConditional requests, caching
Retry-AfterSeconds to wait after 429/503
Security (responses)Strict-Transport-Security, X-Content-Type-Options: nosniff

Auth​

Schemecurl
Basiccurl -u user:pass URL
Bearercurl -H 'Authorization: Bearer <TOKEN>' URL
API key headercurl -H 'x-api-key: <KEY>' URL
Cookie tokencurl -H 'Cookie: token=<TOKEN>' URL
OAuth 2.0 client credentialscurl -u <client_id>:<client_secret> -d 'grant_type=client_credentials' <TOKEN_URL> β†’ use the access_token as Bearer

Decode a JWT's payload to check claims (expiry exp, roles) β€” for test tokens only, never paste production tokens into websites:

echo '<JWT>' | cut -d. -f2 | base64 -d 2>/dev/null; echo

curl​

FlagDoes
-X METHODMethod
-H 'K: V'Header (repeatable)
-d '…' / -d @body.jsonBody inline / from a file
--json '…'Body + JSON headers in one (curl 7.82+)
-F 'file=@photo.jpg'Multipart upload
-G --data-urlencode 'q=a b'Encoded query parameter
-i / -I / -vHeaders + body / headers only / everything
-s / -SSilent / but show errors
-o file / -o /dev/nullSave / discard body
-w '%{http_code}\n'Print the status
-w '%{time_total}\n'Print total time
-LFollow redirects
--max-time 10Give up after 10 s
-kIgnore TLS errors (test environments only)

Postman scripts​

pm.test('status is 200', () => pm.response.to.have.status(200));
pm.test('fast enough', () => pm.expect(pm.response.responseTime).to.be.below(1000));
pm.test('JSON body', () => pm.response.to.be.json);
const body = pm.response.json();
pm.test('has id', () => pm.expect(body).to.have.property('bookingid'));
pm.test('price is a number', () => pm.expect(body.booking.totalprice).to.be.a('number'));
pm.collectionVariables.set('bookingId', body.bookingid); // use as {{bookingId}}
pm.environment.get('baseUrl'); // read an environment variable

Variable scopes, narrowest wins: local β†’ data β†’ environment β†’ collection β†’ global.

Newman​

npx newman run collection.json -e env.json                    # run
npx newman run collection.json -e env.json -n 3 # 3 iterations
npx newman run collection.json -d data.csv # data-driven: one iteration per row
npx newman run collection.json -r cli,junit --reporter-junit-export results/newman.xml # JUnit for CI
npx newman run collection.json --folder "Smoke" # one folder only

Newman exits with a non-zero code when any assertion fails, so CI fails too.

Same request, five tools​

Create a booking and check the status:

# curl
curl -s -X POST https://restful-booker.herokuapp.com/booking \
-H 'Content-Type: application/json' -H 'Accept: application/json' -d @booking.json
# Python β€” requests + pytest
res = requests.post(f"{BASE_URL}/booking", json=booking, headers={"Accept": "application/json"})
assert res.status_code == 200
// TypeScript β€” Playwright request fixture
const res = await request.post('/booking', { data: booking, headers: { Accept: 'application/json' } });
expect(res.status()).toBe(200);
// Java β€” REST Assured
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(booking)
.when().post("/booking")
.then().statusCode(200).body("booking.firstname", equalTo("Asha"));
// Postman β€” Tests tab
pm.test('created', () => pm.response.to.have.status(200));

GraphQL​

curl -s -X POST <URL> -H 'Content-Type: application/json' \
-d '{"query":"query($c: ID!){ country(code: $c){ name } }","variables":{"c":"IN"}}'
CheckWhy
errors array is absentErrors often come with HTTP 200
data has exactly the requested fieldsOver-fetching and leaks
Deep / repeated nesting is limitedOne query can overload the server
Introspection off in production (if policy says so)Hides the schema from attackers
Mutations validate input and permissionsSame as REST writes

Endpoint checklist​

[ ] Happy path: right status, body values, types (schema), headers
[ ] Saved: read back after create / update / delete
[ ] Required fields: each one missing β†’ 400/422 with a clear message
[ ] Types: string for number, number for string, null, array for object
[ ] Limits: empty, max length, max+1, negative, zero, huge numbers
[ ] Business rules: dates in order, totals match, states allowed
[ ] Auth: no token β†’ 401; bad/expired token β†’ 401; other user β†’ 403/404; wrong role β†’ 403
[ ] Not found: unknown id β†’ 404; DELETE twice β†’ 404/204, not 405/500
[ ] Idempotency: PUT/DELETE repeated; POST retried with the same idempotency key
[ ] Lists: empty result, paging, filters, sorting, maximum page size
[ ] Errors never show stack traces or internal details
[ ] Response time within the agreed limit

Negative test ideas​

AreaTry
BodyEmpty body, invalid JSON ({"a":), JSON array instead of object, extra unknown fields
Strings"", " ", 10,000 chars, emoji, <script>, ' OR 1=1 --, ../../etc/passwd
Numbers-1, 0, 0.001, 1e309, "12" (string), NaN
Booleans"true" (string), 1, "yes"
DatesWrong format, 31 April, end before start, far past/future, time zones
IDs0, -1, abc, 999999999, another user's id
HeadersMissing Content-Type, wrong Content-Type, huge headers
MethodsPATCH where only PUT exists, DELETE on a collection

Security checks​

[ ] Every protected endpoint refuses no-token and bad-token requests
[ ] User A can't read/update/delete user B's objects (BOLA)
[ ] Normal users can't call admin functions
[ ] Sending "role", "isAdmin", "price" in a body doesn't change them
[ ] Responses don't leak other users' data, secrets, or internal fields
[ ] Rate limiting on login, sign-up, password reset
[ ] Tokens expire; logout invalidates them
[ ] HTTPS only; HTTP redirects or is refused
[ ] Old API versions (/v1) are removed or equally protected

Bug report for an API​

Title:     [POST /booking] Missing required fields return 500 instead of 400
Env: https://restful-booker.herokuapp.com, <date/time UTC>
Request: curl -s -X POST https://restful-booker.herokuapp.com/booking \
-H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"firstname":"A"}'
Expected: 400 with a list of missing fields
Actual: 500 "Internal Server Error"
Impact: Clients can't tell users what's wrong; server errors trigger alerts

One-liners​

curl -s URL | python3 -m json.tool                     # pretty-print JSON
curl -s URL | jq '.[0].bookingid' # pick a field (jq)
curl -s URL | jq 'length' # count items in a list
curl -s -o /dev/null -w '%{http_code} %{time_total}s\n' URL # status + time
for i in $(seq 1 10); do curl -s -o /dev/null -w '%{http_code}\n' URL; done | sort | uniq -c # quick repeat
curl -s -I -X OPTIONS URL | grep -i access-control # CORS rules

Need more detail? Cheat sheet Β· Best practices Β· Learning path Β· Full guide