API Academy
🌐 English
  • 🌐 English
  • 🌐 繁體中文
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Designing APIs
  • 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. Designing APIs

Analyzing Requirements and Planning Your API

Now that you have your API project set up in Apidog, it's time to start the design process. Before you start designing endpoints or creating schemas, you need to understand what your API should do and who will use it. This might seem obvious, but skipping this step is one of the most common mistakes in API design.
Requirements analysis is the foundation of good API design. Without clear requirements, you might build endpoints that nobody needs, miss critical features, or create an API that's confusing to use.
In this chapter, we'll learn how to analyze requirements and plan your API structure. We'll use the Pet Store User module as our example throughout, walking through the complete process from requirements to a planned API structure.

1. Why Requirements Analysis Matters#

Imagine building a house without blueprints, or cooking a meal without a recipe. You might end up with something, but it probably won't be what you actually need.
The same is true for APIs. Requirements analysis helps you:
Understand the problem you're solving
Identify what features are actually needed
Avoid building unnecessary endpoints
Design an API that users will actually use
Save time by getting it right the first time

What Happens Without Requirements Analysis?#

Without proper requirements analysis, you might:
❌ Create endpoints that don't match user needs
❌ Miss important features (like authentication or validation)
❌ Design inconsistent or confusing APIs
❌ Waste time redesigning later
❌ Build features that nobody uses
Example: If you start designing a User API without understanding that users need to log in, you might forget to include authentication endpoints. Then you'd have to redesign everything later.

2. How to Collect and Analyze Requirements#

Requirements analysis is a systematic process. Let's break it down into steps:

Step 1: Identify Business Goals#

Start by understanding why you're building this API. What problem does it solve?
Example for Pet Store User Module:
Goal: Allow customers to create accounts and manage their information
Problem: Customers need a way to save their preferences, view order history, and maintain their profile
Value: Better customer experience, personalized service, order tracking

Step 2: Determine API Use Cases#

Think about how the API will be used. What are the specific scenarios?
Example use cases for User API:
1.
New customer registration: A new user wants to create an account
2.
User login: An existing user wants to log in to access their account
3.
View profile: A logged-in user wants to see their account information
4.
Update profile: A user wants to change their email or phone number
5.
Manage preferences: A user wants to update their newsletter preferences
6.
Account deletion: A user wants to delete their account

Step 3: Identify User Roles and Permissions#

Who will use your API, and what can they do?
For Pet Store User API:
Public users (not logged in):
Can create a new account
Can log in
Authenticated users:
Can view their own profile
Can update their own profile
Can manage their preferences
Can log out
Can delete their own account
System/Admin (future consideration):
Might need to view all users (not in initial scope)

Step 4: Understand Data Flow and Business Rules#

How does data move through your system? What are the rules?
For User API:
When a user registers, they must provide email, first name, and last name
Email must be unique (no duplicate accounts)
Password should never be returned in API responses
Users can only access their own data
User preferences are optional and have defaults

3. Identifying Core Resources#

Once you understand the requirements, the next step is to identify resourcesβ€”the main entities your API will manage.

What Is a Resource?#

A resource is a thing that your API manages. In REST APIs, resources are typically:
Nouns (not verbs)
Things you can create, read, update, or delete
Things that have properties
Examples of resources:
Users
Orders
Products
Pets
Categories

How to Extract Resources from Requirements#

Look at your use cases and identify the main "things" being managed:
From our User API use cases:
βœ… User β€” the main resource (users create accounts, view profiles, etc.)
❌ "Login" β€” this is an action, not a resource
❌ "Registration" β€” this is an action, not a resource
Wait, but what about login? Login is an operation on the User resource, not a resource itself. We'll handle it as a special endpoint.

Resource Relationships#

Resources often relate to each other. Understanding these relationships helps you design better APIs.
For Pet Store (beyond User module):
A User can have many Orders (one-to-many)
An Order belongs to one User (many-to-one)
A Pet can have many Tags (many-to-many)
For User module (current scope):
A User has one set of Preferences (one-to-one)
This is a nested object, not a separate resource

4. Determining Required Operations#

Now that you know your resources, determine what operations (actions) can be performed on them.

Standard CRUD Operations#

For most resources, you'll need CRUD operations:
OperationHTTP MethodPurposeExample
CreatePOSTAdd a new resourceCreate a new user
ReadGETRetrieve a resourceGet user information
UpdatePUT/PATCHModify a resourceUpdate user profile
DeleteDELETERemove a resourceDelete user account

Special Operations#

Beyond CRUD, you might need special operations:
For User API:
Login β€” authenticate and get a token
Logout β€” invalidate the session token
These don't fit the standard CRUD pattern, so they get their own endpoints.

Operations for User Resource#

Based on our requirements analysis:
OperationHTTP MethodEndpointDescription
Create UserPOST/usersRegister a new user account
Get UserGET/users/{id}Retrieve user information
Update UserPUT/users/{id}Update user profile
Delete UserDELETE/users/{id}Delete user account
LoginPOST/user/loginAuthenticate and get token
LogoutPOST/user/logoutInvalidate session token
Note: Notice that login/logout use /user (singular) instead of /users (plural). This is a common convention for operations that don't operate on a specific resource instance.

5. Planning Endpoint Structure#

Now let's map your resources and operations to actual endpoints (URLs).

From Resources and Operations to Endpoints#

The mapping is straightforward:
Resource: User
Operations:
  - Create β†’ POST /users
  - Read β†’ GET /users/{id}
  - Update β†’ PUT /users/{id}
  - Delete β†’ DELETE /users/{id}
  - Login β†’ POST /user/login (special operation)
  - Logout β†’ POST /user/logout (special operation)

RESTful Path Design Principles#

When designing paths, follow these principles:
1.
Use plural nouns for collections:
βœ… /users (collection of users)
❌ /user (unless it's a special operation)
2.
Use path parameters for specific resources:
βœ… /users/{id} (specific user)
❌ /users/getById?id=123 (use query params for filtering, not identification)
3.
Keep paths hierarchical:
βœ… /users/{id}/orders (orders for a user)
❌ /userOrders?userId=123 (less RESTful)
4.
Use consistent naming:
βœ… /users/{id}
❌ /users/{userId} (redundant - we know it's a user ID)

Complete Endpoint List for User Module#

Here's our complete endpoint plan:
POST   /users           - Create a new user
GET    /users/{id}      - Get user by ID
PUT    /users/{id}      - Update user
DELETE /users/{id}      - Delete user
POST   /user/login      - User login
POST   /user/logout     - User logout

Endpoint Grouping and Organization#

In Apidog, you can organize endpoints using:
Folders β€” group related endpoints
Tags β€” categorize endpoints (e.g., "User", "Authentication")
Modules β€” separate different functional areas
For the User module, we might organize like this:
User Module/
  β”œβ”€β”€ User Management/
  β”‚   β”œβ”€β”€ POST /users
  β”‚   β”œβ”€β”€ GET /users/{id}
  β”‚   β”œβ”€β”€ PUT /users/{id}
  β”‚   └── DELETE /users/{id}
  └── Authentication/
      β”œβ”€β”€ POST /user/login
      └── POST /user/logout

6. Identifying Data Requirements#

Finally, determine what data each resource needs. What fields are required? What are optional?

Data Requirements for User Resource#

Based on our use cases, a User needs:
Required Fields:
id β€” unique identifier (generated by system)
email β€” for login and communication (must be unique)
firstName β€” user's first name
lastName β€” user's last name
createdAt β€” when the account was created (generated by system)
Optional Fields:
phone β€” phone number (for contact)
preferences β€” user preferences object
newsletter β€” whether to receive newsletter (boolean)
notifications β€” whether to receive notifications (boolean)
Authentication Fields:
password β€” for login (never returned in responses, write-only)

Field Relationships#

Some fields relate to each other:
preferences is a nested object within User (not a separate resource)
id and createdAt are read-only (set by system)
password is write-only (never returned)

Data Validation Requirements#

Each field needs validation rules:
FieldTypeValidation Rules
idstringPattern: usr_[A-Za-z0-9]{16}, read-only
emailstringValid email format, unique, required
firstNamestringRequired, max 50 characters
lastNamestringRequired, max 50 characters
phonestringOptional, E.164 format if provided
passwordstringRequired for creation, write-only, min 8 characters
preferences.newsletterbooleanOptional, default: false
preferences.notificationsbooleanOptional, default: true
createdAtdate-timeRead-only, ISO 8601 format

7. Putting It All Together: The User API Plan#

Let's summarize everything we've planned:

Resources#

User β€” the main resource

Endpoints#

POST   /users           - Create user
GET    /users/{id}      - Get user
PUT    /users/{id}      - Update user
DELETE /users/{id}      - Delete user
POST   /user/login      - Login
POST   /user/logout     - Logout

Data Model (Summary)#

User object with:
Required: id, email, firstName, lastName, createdAt
Optional: phone, preferences
Authentication: password (write-only)

Authentication#

Login endpoint returns a token
Token required for: GET, PUT, DELETE /users/{id}, and logout
Create and login endpoints are public

8. Key Takeaways#

Requirements analysis and planning are essential before you start designing:
1.
Requirements analysis ensures you build what's actually needed
2.
Use cases help you understand how the API will be used
3.
Resources are the main entities your API manages (nouns)
4.
Operations are the actions performed on resources (CRUD + special operations)
5.
Endpoints map resources and operations to URLs
6.
Data requirements define what fields each resource needs
7.
Planning saves time by getting the structure right from the start

Now that you have a clear plan for the User API, you're ready to design the detailed data models and implement them as schemas in Apidog. In the next chapter, we'll learn how to design and implement your data modelsβ€”creating schemas with the exact structure, types, and validation rules.
Let's continue with Designing and Implementing Data Models.
Modified atΒ 2025-12-25 09:47:07
Previous
Creating Your First API Project
Next
Designing Data Models
Built with