API testing is the backbone of modern software quality assurance. Whether you're a QA engineer, a backend developer, or a DevOps practitioner, understanding how to systematically test REST APIs is essential for delivering reliable software. This guide covers everything from HTTP fundamentals to advanced testing strategies.
For hands-on testing, try our free online API tester — but first, let's build your knowledge foundation.
API testing sends requests to an API endpoint and verifies the response against expected results. Unlike UI testing, API testing directly validates the business logic layer — the server's processing, data manipulation, authentication, and business rules — without the overhead of a browser interface.
REST APIs use standard HTTP methods to perform CRUD operations on resources. Understanding each method's semantics, idempotency, and safety properties is fundamental.
| Method | Operation | Idempotent | Safe | Has Body | Common Status |
|---|---|---|---|---|---|
GET | Read a resource | Yes | Yes | No | 200, 404 |
POST | Create a resource | No | No | Yes | 201, 400, 409 |
PUT | Replace a resource | Yes | No | Yes | 200, 204, 404 |
PATCH | Partial update | No* | No | Yes | 200, 204 |
DELETE | Remove a resource | Yes | No | Optional | 204, 404 |
HEAD | Get headers only | Yes | Yes | No | 200 |
OPTIONS | Get allowed methods | Yes | Yes | No | 200 |
*PATCH is idempotent only if the operation itself is idempotent (e.g., setting a field to a value). It's implementation-dependent.
Status codes are the API's primary communication mechanism. Testing the correct status code for each scenario is the first line of verification.
| Code | Name | Meaning | When to Expect |
|---|---|---|---|
| 1xx | Informational | ||
| 100 | Continue | Client should continue sending body | Large uploads with Expect header |
| 2xx | Success | ||
| 200 | OK | Request succeeded | GET, PUT, PATCH, DELETE responses |
| 201 | Created | Resource created successfully | POST creating a new resource |
| 204 | No Content | Success, no body returned | DELETE or PUT with no response body |
| 3xx | Redirection | ||
| 301 | Moved Permanently | Resource permanently relocated | API version migration |
| 304 | Not Modified | Cached version is still valid | Conditional GET with ETag/If-None-Match |
| 4xx | Client Errors | ||
| 400 | Bad Request | Malformed request syntax | Invalid JSON, missing required fields |
| 401 | Unauthorized | Authentication required/failed | Missing or invalid token |
| 403 | Forbidden | Authenticated but not authorized | Insufficient permissions |
| 404 | Not Found | Resource doesn't exist | Invalid ID in URL path |
| 409 | Conflict | Request conflicts with state | Duplicate email on registration |
| 422 | Unprocessable Entity | Semantic validation errors | Valid JSON but invalid data (e.g., email format) |
| 429 | Too Many Requests | Rate limit exceeded | Exceeded API quota |
| 5xx | Server Errors | ||
| 500 | Internal Server Error | Unhandled server exception | Bug in server code |
| 502 | Bad Gateway | Upstream server returned invalid response | Reverse proxy / load balancer issue |
| 503 | Service Unavailable | Server temporarily overloaded | Maintenance or capacity issue |
Professional API testing goes beyond happy paths. Here are the essential test categories every API test suite should cover:
Verify that each endpoint returns the correct data, status code, and response format for valid inputs.
Test how the API handles invalid, missing, and malformed inputs.
| Test Case | Input | Expected Status | Expected Behavior |
|---|---|---|---|
| Missing required field | POST /users with no name | 400 or 422 | Error message listing missing field |
| Invalid data type | age: "twenty" | 400 or 422 | Error about type mismatch |
| Out of range value | age: -5 | 400 or 422 | Error about valid range |
| SQL injection attempt | name: "'; DROP TABLE--" | 400 | Input sanitized/rejected, DB safe |
| XSS attempt | name: "<script>alert(1)</script>" | 200 (but sanitized) | Output escaped in response |
| Extremely long string | name: 10,000 chars | 400 or 422 | Rejected by length validation |
| Scenario | Expected Result |
|---|---|
| Request with no auth token | 401 Unauthorized |
| Request with expired token | 401 Unauthorized |
| Request with invalid token | 401 Unauthorized |
| Valid token, insufficient permissions | 403 Forbidden |
| Valid token, correct permissions | 200 OK |
| Token from different user accessing another's resource | 403 Forbidden |
A well-designed API returns consistent error responses. Test that errors follow a standard format:
| Method | Header Format | Security | Best For |
|---|---|---|---|
| Bearer Token (JWT) | Authorization: Bearer <token> | High | Most modern APIs |
| API Key | X-API-Key: <key> | Medium | Server-to-server, public APIs |
| Basic Auth | Authorization: Basic <base64> | Low | Internal tools, legacy systems |
| OAuth 2.0 | Authorization: Bearer <token> | Very High | Third-party access delegation |
| HMAC | Custom signed header | Very High | Payment APIs (AWS, Stripe) |
Set performance thresholds for each endpoint. A well-designed API should respond within these guidelines:
| Operation Type | Acceptable Latency | Target Latency |
|---|---|---|
| Simple CRUD (GET/POST) | < 500ms | < 200ms |
| Complex query/aggregation | < 2s | < 1s |
| File upload/download | Depends on size | Proportional |
| Batch operations | < 5s | < 3s |
Never test with production data. Create dedicated test datasets that cover:
Use JSON Schema validation to ensure responses match the documented contract. This catches breaking changes early.
Send requests exceeding the rate limit and verify:
Send requests, inspect responses, and debug APIs directly in your browser.
Open API Tester →Effective API testing is a skill that combines HTTP knowledge, systematic thinking, and attention to detail. By covering functional tests, input validation, authentication, error handling, and performance, you build confidence in your API's reliability. Start with the scenarios outlined in this guide, automate what you can, and iterate as your API evolves.