← Back to libraryQuestion 188 of 273
🌐API TestingBeginner

How APIs Work - Request-Response Flow

📌 Definition:

APIs operate on a request-response model where a client sends structured requests to a server, which processes them and returns structured responses. This is the fundamental communication pattern.

📖 Detailed Explanation:

The API workflow is like a restaurant: You (client) place an order (request) with specific details. The kitchen (server) receives the order, processes it according to your specifications, and delivers the meal (response). The API acts as the intermediary that formats your order, validates it, processes it through business logic, and returns results in a standard format. The beauty of APIs is that the client doesn't need to know how the server processes requests internally - it only needs to know the contract (input format and output format). This separation of concerns allows different systems to communicate seamlessly even if they're built with different technologies.

🔑 Key Points:
  • APIs abstract internal logic - clients never see implementation details
  • Clients never access databases directly - all communication goes through the API
  • Requests and responses follow predefined formats (JSON, XML, etc.)
  • HTTP methods (GET, POST, PUT, DELETE) define the action type
  • Status codes indicate request success or failure
🔄 Workflow:
  • 1. Client prepares and sends a structured request (HTTP method + endpoint + parameters + headers)
  • 2. Request travels over the network to the API server
  • 3. API server receives and parses the request
  • 4. Middleware and authentication layers validate the request
  • 5. Business logic processes the request and performs data operations
  • 6. Database operations are executed (if needed)
  • 7. Response is formatted and prepared by the server
  • 8. Response travels back over the network to the client
  • 9. Client receives and parses the response
📎 Request Response Example:
Request:
Method:

GET

Endpoint:

/api/users/123

Headers:

Authorization: Bearer token, Content-Type: application/json

Body:

None (for GET requests)

Response:
Status Code:

200 OK

Headers:

Content-Type: application/json

Body:

{ id: 123, name: 'John', email: 'john@example.com' }

🎯 Scenario-Based Interview Question:

Scenario: You're testing a user registration API. During testing, you send a POST request to /api/users. The API returns 200 OK but you notice the response takes 3 seconds. Walk through what could be happening in each step of the request-response flow, and explain how you'd diagnose the slowness.