HTTP Basics for Testers: Methods, Status Codes, Headers
Every API call is an HTTP request and a response. Once you can read both, API testing is mostly checking that the response is right for the request.
Parts of a request
POST https://jsonplaceholder.typicode.com/posts?draft=false
Content-Type: application/json
Authorization: Bearer eyJhbGciOi...
{
"title": "My first post",
"body": "Hello",
"userId": 1
}
- Method:
POST, what you want to do. - URL: the endpoint,
/posts. After?come query parameters such asdraft=false. - Headers: extra information, like the body format and who you are.
- Body: the data you send, usually JSON. GET requests normally have no body.
HTTP methods
| Method | Meaning | Example |
|---|---|---|
| GET | Read data | GET /users/1 |
| POST | Create something new | POST /posts |
| PUT | Replace a whole record | PUT /posts/1 |
| PATCH | Change some fields | PATCH /posts/1 |
| DELETE | Remove a record | DELETE /posts/1 |
Path parameters are part of the URL, like the 1 in /users/1. Query parameters filter or sort: /posts?userId=1.
Status codes
| Code | Meaning | When you see it |
|---|---|---|
| 200 OK | Success | GET, PUT, PATCH worked |
| 201 Created | A new record was made | POST worked |
| 204 No Content | Success, nothing to return | Often after DELETE |
| 400 Bad Request | Your data is wrong | Missing or invalid field |
| 401 Unauthorized | Not logged in | No token or a bad token |
| 403 Forbidden | Logged in but not allowed | A user tries an admin action |
| 404 Not Found | It does not exist | GET /users/99999 |
| 409 Conflict | Clashes with existing data | Registering the same email twice |
| 422 Unprocessable | Valid format, breaks a rule | Quantity of 0 |
| 429 Too Many Requests | Rate limit hit | Too many calls too fast |
| 500 Server Error | The server crashed | Always a bug worth reporting |
Quick memory trick: 2xx success, 4xx the client (you) did something wrong, 5xx the server did something wrong.
Response headers worth checking
Content-Type: application/json: the body really is JSON.Location: after a 201, where the new record lives.Cache-Control, CORS headers and security headers, for non-functional checks.
Try it with curl
curl -i https://jsonplaceholder.typicode.com/users/1
curl -i -X POST https://jsonplaceholder.typicode.com/posts \
-H "Content-Type: application/json" \
-d '{"title":"Hello","body":"First post","userId":1}'
-i shows the status line and headers. The second call should return 201 Created.
Tool: paste any response into the free JSON formatter to read it easily.