Junior
What are the status codes in server responses?
sobes.tech AI
Answer from AI
1xx Informational: The request has been received, and the process is continuing. 2xx Success: The request was successfully received, understood, and accepted. 3xx Redirection: Further action must be taken to complete the request. 4xx Client Error: The request contains incorrect syntax or cannot be fulfilled. 5xx Server Error: The server failed to fulfill a valid request.
Examples of common statuses:
| Status | Description | Category |
|---|---|---|
| 100 | Continue | Informational |
| 200 | OK | Success |
| 201 | Created | Success |
| 204 | No Content | Success |
| 301 | Moved Permanently | Redirection |
| 302 | Found | Redirection |
| 400 | Bad Request | Client Error |
| 401 | Unauthorized | Client Error |
| 403 | Forbidden | Client Error |
| 404 | Not Found | Client Error |
| 500 | Internal Server Error | Server Error |
| 502 | Bad Gateway | Server Error |
| 503 | Service Unavailable | Server Error |
For automated API testing, it is important to check not only the response body but also the correct status code.
import requests
url = "https://example.com/api/resource"
response = requests.get(url)
# Check for status 200 OK
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}"