API Academy
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
  1. API Fundamentals
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
  1. API Fundamentals

What are Responses in an API?

Once you send an API request, the next step is understanding the response. The response tells you whether your request succeeded and (if it did) returns the data you asked for.
Learning how to read responses is essential for debugging, building applications, and understanding how APIs behave.
In this article, weโ€™ll use the Petstore API to explain how to interpret response structure, status codes, and response bodies.

1. What Is an API Response?#

An API response consists of three main parts:
1.
Status Code
2.
Headers
3.
Body (usually JSON)
Example:
HTTP/1.1 200 OK
Content-Type: application/json
{
  "id": "pet_1Nv0FGQ9RKHgCVdK",
  "name": "Fluffy",
  "species": "DOG",
  "status": "AVAILABLE"
}
Each part provides different information about the result of your request.

2. Status Code โ€” The First Thing to Check#

The HTTP status code tells you whether the request worked.
The most important and most common code is:

200 OK#

This means:
Your request succeeded
The server returned the expected data
You can trust the response body
Other common status codes include:
CodeMeaningWhen It Happens
400 Bad RequestYour request is invalidMissing fields, wrong types
401 UnauthorizedAuthentication failedMissing/invalid token
404 Not FoundResource does not existWrong ID or path
500 Server ErrorProblem on server sideUnrelated to your request
When reading API docs, look for:
Which status codes you should expect
Whether the API uses different bodies for different codes

3. Response Headers (For Metadata)#

Headers describe the response itself, not the data. Common headers include:
Content-Type: application/json โ†’ tells you the format
Date: โ†’ server timestamp
RateLimit-Remaining: โ†’ how many requests you have left
These can be useful but are usually less important than the response body for beginners.

4. Response Body โ€” The Actual Data#

Most modern APIs return their response body as JSON.
This is where the actual data lives.
Example response body from Get a pet:
{
  "id": "pet_1Nv0FGQ9RKHgCVdK",
  "name": "Fluffy",
  "species": "DOG",
  "breed": "Golden Retriever",
  "ageMonths": 24,
  "status": "AVAILABLE",
  "photos": [
    "https://cdn.petstoreapi.com/pets/pet_1Nv0FGQ9RKHgCVdK/photo1.jpg"
  ]
}
To understand this body, you should compare it to the APIโ€™s response schema.

5. Matching Response Body to the Schema#

Good API docs define a response schema that describes:
Field names
Types (string, number, object, array)
Required / optional
Nested structure
Example Petstore schema:
Pet

By comparing the response to this table, you can confirm:
The API returned all required fields
Types match
The data structure is correct
If anything doesnโ€™t match, your application may break โ€” which is why schemas are so important.

6. Example: Get a pet#

Request
GET /pets/pet_1Nv0FGQ9RKHgCVdK
Successful Response
HTTP/1.1 200 OK
{
  "id": "pet_1Nv0FGQ9RKHgCVdK",
  "name": "Fluffy",
  "species": "DOG",
  "status": "AVAILABLE"
}
Example Error: Pet Not Found
HTTP/1.1 404 Not Found
{
  "code": 1,
  "type": "error",
  "message": "Pet not found"
}
Seeing different response structures for different status codes is common.
This is why API docs usually include both success and error examples.

7. Key Takeaways#

API responses contain status codes, headers, and a body.
200 OK is the most important success code.
The response body (usually JSON) contains the actual data you are interested in.
Use the response schema to understand and validate the structure.
Knowing how to read responses helps you build reliable applications and debug issues quickly.

Now that you know how to read and understand API responses, youโ€™ll be able to work with API data more confidently and troubleshoot issues as they come up. In the next section, weโ€™ll introduce the OAS(OpenAPI Specification)โ€”a powerful standard for describing APIsโ€”that makes exploring, testing, and documenting APIs much easier.
Modified atย 2025-12-25 09:31:13
Previous
Request Body
Next
API Specification & OAS
Built with