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

Designing Endpoints

Now that you have your schemas designed and your project structure organized, it's time to create the actual endpoints. Endpoints are the entry points to your APIβ€”they define how clients interact with your resources.
In this chapter, we'll learn how to design and create endpoints in Apidog, focusing on how to configure requests and responses with schemas and examples. We'll use the endpoint plan we created earlier and implement the User module endpoints.

1. What Is an Endpoint?#

An endpoint is a specific URL path combined with an HTTP method that defines a single operation in your API. For example:
POST /users β€” Create a new user
GET /users/{id} β€” Get a specific user
PUT /users/{id} β€” Update a user
DELETE /users/{id} β€” Delete a user
Each endpoint consists of:
HTTP Method β€” What action to perform (GET, POST, PUT, DELETE)
Path β€” Where the resource is located (e.g., /users/{id})
Request β€” Parameters, headers, body (if needed)
Response β€” What the API returns (status codes, data structure, examples)

2. Creating POST /users Endpoint (Create User)#

Let's start by creating the POST /users endpoint to create a new user. This endpoint demonstrates how to configure request bodies with schemas and responses.

Step 1: Create the Endpoint#

1.
In your Apidog project, navigate to the APIs section β†’ your module
2.
Click "New Endpoint" (or βž• β†’ New Endpoint)
3.
Set method: Select POST
4.
Set path: /users
Important: Always start paths with / to comply with OpenAPI specification
Don't include the base URL (set in environments)
5.
Add metadata:
Name: "Create User"
Description: "Create a new user account in the system"
Tags: "User"
Status: "Developing" (default)

Step 2: Configure Request Body with Schema#

Since this is a POST request, we need a request body:
1.
Go to the Request tab β†’ Body
2.
Select content type: JSON
3.
Click "Schema" and select "User" from your schemas
Apidog will automatically load the User schema structure.

Step 3: Customize Fields for Create Request#

The User schema includes all fields, but for the create user endpoint, we need to adjust:
Fields to hide (not needed in request):
id β€” Generated by system, not provided by client
createdAt β€” Set by system, not provided by client
Fields to add (needed in request but not in base schema):
password β€” Required for account creation
In Apidog:
1.
Hide fields:
Hover on a field in the schema (e.g., id or createdAt)
Click "Hide"
Hidden fields won't appear in the request body
image.png
2.
Add fields:
Click "Add Field" or use field association
Add password field:
Type: string
Required: βœ…
Write-only: βœ… (important for security)
Min length: 8
Description: "User password"
3.
Adjust required/optional:
For create endpoint: email, firstName, lastName, password are required
phone and preferences are optional
Toggle "Required" for each field as needed

Step 4: Generate Request Body Examples#

Apidog can automatically generate request body examples based on your schema:
1.
Click "Add" in the request example section
2.
In the popup, click "Auto-generate"
image.png
3.
Apidog will automatically create example data that:
Matches your schema structure
Includes all visible fields
Uses appropriate data types and formats
Follows validation rules (patterns, formats, etc.)
Generated example:
{
  "email": "jane.smith@example.com",
  "firstName": "Jane",
  "lastName": "Smith",
  "password": "securePassword123",
  "phone": "+14155551234",
  "preferences": {
    "newsletter": true,
    "notifications": false
  }
}
Customize the generated example:
Edit values directly in the JSON editor
Modify to show different scenarios (e.g., minimal fields, edge cases)
Add multiple examples by clicking "Add Example" and generating again
Benefits of auto-generated examples:
Saves time β€” no need to write JSON manually
Always matches your schema β€” ensures consistency
Easy to customize β€” generate first, then edit as needed

Step 5: Configure Response#

Now let's configure what the API returns:
1.
Go to the Response tab
2.
Click "Add Response" (or "Add Blank Response")
3.
Select status code: 201 (Created)
4.
Set content type: application/json
5.
Click "Schema" and select "User" schema
The User schema will be used, and Apidog automatically excludes write-only fields (like password) from responses.

Step 6: Generate Response Examples#

1.
Click "Add Example" in the response section
2.
Click "Auto-generate"
Apidog will create example data that:
Matches your schema structure
Uses appropriate data types
Follows validation rules (patterns, formats, etc.)
Respects field constraints (read-only, write-only)
Automatically excludes write-only fields (like password)
Generated example:
{
  "id": "usr_3Oy2JIS7TMJgEXfM",
  "email": "jane.smith@example.com",
  "firstName": "Jane",
  "lastName": "Smith",
  "phone": "+14155551234",
  "preferences": {
    "newsletter": true,
    "notifications": false
  },
  "createdAt": "2024-01-15T10:30:00Z"
}
Notice that password is automatically excluded (write-only field).
Add multiple response examples:
Click "Add Example" again
Click "Auto-generate" for each new example
Edit the generated JSON to show different scenarios (e.g., user with minimal data)

Step 7: Add Error Responses#

Every endpoint should define error responses:
1.
Click "Add Response"
2.
Add common error responses:
400 Bad Request β€” Invalid input
422 Unprocessable Entity β€” Validation errors
For error responses, you can use a shared Error Response Component (we'll cover this in the next chapter) or define inline with schema and examples.

3. Creating GET /users/{id} Endpoint (Get User)#

Now let's create the GET /users/{id} endpoint to retrieve a user by ID. This endpoint demonstrates how to configure path parameters and responses.

Step 1: Create the Endpoint#

1.
Click "New Endpoint"
2.
Set method: Select GET
3.
Set path: /users/{id}
The {id} is a path parameter (use braces {}, not colons :)
Important: Always start paths with /
4.
Add metadata:
Name: "Get User"
Description: "Retrieve user information by user ID"
Tags: "User"
When you write /users/{id} in the path, Apidog automatically recognizes {id} as a path parameter. You don't need to add it manually.
Note:
In Apidog, use {parameter} syntax in paths, not :parameter
Path parameters are automatically detectedβ€”just write them in the path, then configure their properties

Step 2: Configure Response#

1.
Go to the Response tab
2.
Click "Add Response"
3.
Select status code: 200 (OK)
4.
Set content type: application/json
5.
Click "Schema" and select "User" schema

Step 3: Generate Response Examples#

1.
Click "Add Example"
2.
Click "Auto-generate"
Apidog will generate a response example matching the User schema (excluding write-only fields like password).
Add multiple examples:
Generate additional examples to show different scenarios
Edit to show users with or without optional fields

Step 4: Add Error Responses#

Add common error responses:
404 Not Found β€” User not found
400 Bad Request β€” Invalid user ID format

4. Apidog Features for Request/Response Configuration#

Apidog provides several powerful features for working with requests and responses:

Field Visibility and Association#

Hide fields in requests:
System-generated fields (id, createdAt) shouldn't appear in create requests
Hover on a field and click "Hide" to hide it in requests
Hidden fields won't appear in request body or examples
Add fields via association:
Add fields that are only needed in specific endpoints (like password in create/login)
Fields are associated with the endpoint, not the base schema
Useful for endpoint-specific requirements
Adjust required/optional per endpoint:
Base schema defines defaults
Each endpoint can override required/optional settings
Useful for partial updates (PUT endpoints where all fields are optional)

Automatic Example Generation#

Apidog's Auto-generate feature creates examples automatically:
Request body/Response examples:
Click "Add Example" β†’ "Auto-generate" to create example from response schema
Excludes write-only fields automatically
Creates realistic sample data matching schema constraints
Can generate multiple examples and customize each
Benefits:
Fast β€” Generate examples in seconds
Accurate β€” Always matches your schema
Flexible β€” Edit generated examples to show different use cases

Schema References#

Reference existing schemas instead of duplicating
Changes to schema automatically reflect in all endpoints
Maintains consistency across your API

Multiple Examples#

Add multiple examples for different scenarios
Name examples for clarity
Switch between examples when testing

5. Quick Reference: Other Endpoints#

For the remaining endpoints, follow similar patterns:
PUT /users/{id} (Update user):
Path parameter: {id} (same as GET)
Request body: User schema with all fields optional (partial update)
Hide: id, createdAt
Don't include: password (use separate endpoint)
Response: 200 with User schema
DELETE /users/{id} (Delete user):
Path parameter: {id}
No request body
Response: 204 No Content (no body)
POST /user/login (Login):
Request body: Simple schema with username and password
Response: 200 with token and expiresAt
POST /user/logout (Logout):
No request body (or optional body)
Response: 200 with success message

6. Organizing Endpoints#

After creating endpoints, organize them:
1.
Create folders under Endpoints:
User Management/ β€” POST, GET, PUT, DELETE /users
Authentication/ β€” Login and logout
2.
Drag endpoints into appropriate folders

7. Key Takeaways#

Designing endpoints involves careful configuration of requests and responses:
1.
Use schemas for request and response bodies to maintain consistency
2.
Customize schemas per endpoint using field visibility and associations
3.
Hide system-generated fields in requests (id, createdAt)
4.
Add endpoint-specific fields via field association (like password)
5.
Generate examples automatically from schemas, then customize
6.
Add multiple examples to show different scenarios
7.
Define error responses for comprehensive API documentation
8.
Use schema references to avoid duplication and maintain consistency

Now that you have endpoints with well-configured requests and responses, you can enhance them with reusable components. In the next chapter, we'll learn about using components and reusability to make your API design more efficient.
Let's continue with Using Components and Reusability.
Modified atΒ 2026-02-12 06:23:15
Previous
Designing Data Models
Next
Using Components and Reusability
Built with