← Back to libraryQuestion 251 of 273
📋Software TestingIntermediate

API Testing Fundamentals

📌 Definition:

Testing APIs (Application Programming Interfaces) to verify they work correctly, reliably, securely, and perform well.

📖 Detailed Explanation:

APIs are the backbone of modern applications. Mobile apps use APIs to get data from backend servers. Frontend communicates with backend via APIs. Microservices communicate via APIs. Testing APIs is critical but often overlooked. API bugs are invisible to users (no UI), but they break functionality completely.

📎 Api Basics Detailed:
Http Methods:
MethodPurposeExampleShould Return
GETRetrieve data (read-only, safe, idempotent)GET /api/users/123 retrieves user with ID 123200 OK with user data in response body
POSTCreate new data (creates resource)POST /api/users with body {name: 'John'} creates new user201 Created with new user data
PUTUpdate entire resource (replace)PUT /api/users/123 with body {name: 'Jane'} replaces user data200 OK with updated data
PATCHPartially update resource (modify specific fields)PATCH /api/users/123 with body {email: 'john@new.com'} updates only email200 OK with updated data
DELETEDelete resourceDELETE /api/users/123 deletes user with ID 123204 No Content or 200 OK
Http Status Codes:
CodeMeaningExample
200 OKRequest successfulGET /api/users returns 200 with user list
201 CreatedResource created successfullyPOST /api/users returns 201 with new user
204 No ContentSuccess but no data to returnDELETE /api/users/123 returns 204
400 Bad RequestInvalid request (client error)POST /api/users without required name field
401 UnauthorizedAuthentication requiredAPI request without login token
403 ForbiddenAuthenticated but not authorizedUser tries to access admin endpoint
404 Not FoundResource doesn't existGET /api/users/999 when user doesn't exist
500 Server ErrorInternal server errorUnexpected backend crash
503 UnavailableService temporarily downServer under maintenance
Request Components:
ComponentDescriptionExample
URL/Endpoint/api/users or /api/users/123Points to the resource being accessed
HTTP MethodGET, POST, PUT, DELETESpecifies the action
HeadersContent-Type, Authorization, etc.Content-Type: application/json tells server data is JSON
Body/PayloadData being sent (for POST, PUT, PATCH){name: 'John', email: 'john@example.com'}
Query Parameters?page=1&limit=10Filters or pagination parameters
📎 What To Test Detailed:
Test Category:

Functionality Testing

Tests:
  • Correct response for valid requests - Does GET return expected data?
  • Error handling for invalid requests - Does POST with missing fields return 400?
  • Correct status codes - Does creation return 201, not 200?
  • Response data format - Is data in correct JSON structure?
  • Data validation - Does API reject invalid email format?
Test Category:

Boundary/Edge Case Testing

Tests:
  • Minimum/maximum values - What happens with 0 items or 1000000 items?
  • Empty fields - Does API handle null values correctly?
  • Special characters - Can API handle Unicode, emojis, SQL injection attempts?
  • Duplicate requests - What happens when same request sent twice?
  • Timeout testing - What if request takes >30 seconds?
Test Category:

Security Testing

Tests:
  • Authentication - Are API tokens required? Do expired tokens get rejected?
  • Authorization - Can User A access User B's data? Should return 403.
  • SQL Injection - Can attacker use malicious SQL in parameters?
  • Sensitive data exposure - Are passwords returned in response? They shouldn't be.
  • Rate limiting - Can attacker make 10000 requests/second or is it throttled?
Test Category:

Performance Testing

Tests:
  • Response time - Does API respond in <200ms? <1000ms?
  • Throughput - Can API handle 1000 requests per second?
  • Scalability - Does response time increase when database grows?
  • Resource usage - Does API consume excessive memory/CPU?
Test Category:

Data Integrity Testing

Tests:
  • Consistency - If API is called twice with same data, is result identical?
  • Atomicity - If CREATE fails midway, is data partially saved? (Should be all-or-nothing)
  • Referential integrity - Can you delete a user if they have orders? (Database constraints)
📎 Real World Scenario:
Api Endpoint:

POST /api/orders/checkout

Test Case 1:
Name:

Valid Checkout

Request:

POST /api/orders/checkout {userId: 123, items: [{productId: 1, qty: 2}], paymentMethod: 'card'}

Expected Response:

201 Created {orderId: 999, totalAmount: 100, status: 'confirmed'}

What To Verify:

Order created, correct total calculated, status is confirmed

Test Case 2:
Name:

Invalid User

Request:

POST /api/orders/checkout {userId: 99999, items: [...]}

Expected Response:

400 Bad Request {error: 'User not found'}

What To Verify:

Returns 400, not 500. Error message is clear.

Test Case 3:
Name:

Insufficient Stock

Request:

POST /api/orders/checkout {userId: 123, items: [{productId: 1, qty: 1000}]}

Expected Response:

409 Conflict {error: 'Only 50 items in stock'}

What To Verify:

Returns 409, not silent failure. User knows why order failed.

📎 Common Api Testing Tools:
ToolUseFeatures
PostmanManual and automated API testing, collection sharingEasy UI, good for beginners
Rest AssuredJava-based API testing in CI/CD pipelinesJava syntax, integrates with TestNG
SoapUISOAP and REST API testingLoad testing, security scanning
InsomniaAPI testing with good UXTeam collaboration, environment management
JMeterPerformance/load testing for APIsSimulate thousands of concurrent users
Swagger/OpenAPIAPI documentation and auto-generated testsContract-driven testing
🎯 Scenario-Based Interview Question:

Your user API has GET /api/users/123. Without authentication, this returns all user data including passwords. What would you do?

💡 Quick Tip:

🔗 API testing = Testing data flow without UI. Master this to advance your QA career. Postman is your best friend.

💡 Interview Focus:

API testing is modern, essential skill. Interviewers value candidates who understand APIs deeply.