User Manual

This manual provides a detailed guide to Apifox's core features and usage, including project management, interface design, debugging, mocking, automated testing, and more.

Project Management

Creating a Project

In Apifox, a project is the top-level unit for organizing APIs.

# Steps to create a new project
1. Click the "+" next to the "Project" list on the left
2. Enter a project name
3. Choose the project type
4. Choose a base template (optional)
5. Click "Create"

Project Settings

Each project has its own independent settings:

  • Basic Info: Project name, description, icon
  • Environment Variables: Define variables for different environments like development, testing, and production
  • Authentication: Set global authentication methods
  • Export/Import: Import and export project data

Environment Management

Apifox supports multi-environment configuration:

# Using environment variables
Reference environment variables in requests using {{variableName}}
Example: {{baseUrl}}/api/users

Switching environments: Click the environment selector at the top to choose different environments

Interface Design

Creating an Interface

An interface is a specific API definition:

# Steps to create an interface
1. In your project, click "+" and select "New Interface"
2. Fill in the basic information:
   - Interface name: User List
   - Request path: /api/users
   - Request method: GET
3. Define request parameters
4. Define response structure
5. Save

Request Parameters

These types of request parameters are supported:

  • Path parameters: Like the id in /api/users/:id
  • Query parameters: In the URL like ?name=test
  • Request headers: Like Authorization
  • Request body: JSON, form, XML, and other formats

Response Definitions

Define success and failure responses for each interface:

{
  "Success Response 200": {
    "id": 1,
    "name": "Zhang San",
    "email": "[email protected]"
  },
  "Error Response 404": {
    "code": 404,
    "message": "User not found"
  }
}

Interface List Management

Group management is supported—you can organize interfaces by module or functionality:

  • Drag and drop to reorder
  • Batch operations (batch delete, batch export, etc.)
  • Search and filter

Interface Debugging

Sending Requests

On the interface detail page, click "Send" to send a request:

# Basic debugging steps
1. Open the interface
2. Select an environment
3. Set parameter values
4. Click "Send"
5. View the response

Authentication Settings

Multiple authentication methods are supported:

  • None: No authentication
  • Bearer Token: JWT authentication
  • Basic Auth: Basic authentication
  • OAuth 2.0: OAuth2 authentication
  • Custom authentication: Custom auth headers as needed

Pre-request Scripts

You can set up scripts that run before a request is sent:

// Example: Add a timestamp
const timestamp = Date.now();
pm.request.headers.append('X-Timestamp', timestamp);

// Example: Generate a random ID
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
});
pm.request.headers.append('X-Request-Id', uuid);

Post-response Scripts

You can set up scripts that run after receiving a response:

// Example: Extract response data
const response = pm.response.json();
console.log('Response data:', response);

// Example: Set an environment variable
pm.environment.set('access_token', response.data.token);

API Mocking

Smart Mock

One of Apifox's most powerful features—just define your data structure, and the system automatically generates mock data:

# Enabling Smart Mock
1. Open the interface
2. Click the "Mock" tab
3. Enable "Smart Mock"
4. Save

Mock Rules

Custom mock rules are supported:

  • @string: Generate random strings
  • @integer: Generate random integers
  • @float: Generate random floats
  • @boolean: Generate random booleans
  • @date: Generate random dates
  • @email: Generate random emails
  • @url: Generate random URLs
  • @guid: Generate UUIDs

Examples

{
  "id": "@integer",
  "name": "@string",
  "email": "@email",
  "age": "@integer(18, 60)",
  "createdAt": "@date"
}

Generated mock data:

{
  "id": 12345,
  "name": "kF9s2m",
  "email": "[email protected]",
  "age": 35,
  "createdAt": "2024-03-15"
}

Mock Server

Apifox provides a built-in Mock server:

# Getting the Mock URL
On the interface detail page, copy the Mock URL
Example: https://mock.apifox.com/api/users

Automated Testing

Creating Test Cases

# Steps to create a test
1. Open the interface
2. Click the "Test" tab
3. Click "Create Test"
4. Set the test case name
5. Add assertions
6. Save

Assertion Types

Multiple assertions are supported:

  • Status code assertion: Check the response status code
  • JSON assertion: Check response JSON data
  • Response time assertion: Check response time
  • Response header assertion: Check response headers

Examples

// Status code assertion
pm.test("Status code is 200", function() {
    pm.response.to.have.status(200);
});

// JSON assertion
pm.test("Returns user list", function() {
    const jsonData = pm.response.json();
    pm.expect(jsonData.code).to.eql(0);
    pm.expect(jsonData.data).to.be.an('array');
});

// Response time assertion
pm.test("Response time is less than 500ms", function() {
    pm.expect(pm.response.responseTime).to.be.below(500);
});

Test Suites

You can organize test cases from multiple interfaces into test suites:

  1. Create a test suite
  2. Add test cases
  3. Set execution order
  4. Run the suite

Generating Test Reports

After running tests, you can generate detailed test reports:

  • Pass rate statistics
  • Failed case analysis
  • Response time statistics

Team Collaboration

Inviting Members

# Inviting team members
1. Go to project settings
2. Click "Member Management"
3. Click "Invite Member"
4. Enter the member's email
5. Set role permissions
6. Send the invitation

Roles and Permissions

  • Admin: Full project permissions
  • Editor: Can edit interfaces and run tests
  • Viewer: Can only view, cannot edit

Real-time Sync

Once team members log in, project data syncs automatically in real-time:

  • Interface changes sync automatically
  • Test results sync automatically
  • Team members always see the latest content

Comments

You can add comments on interfaces:

  1. Open the interface
  2. Click "Comment"
  3. Enter comment content
  4. @mention team members

Data Import and Export

Supported Formats

Import:

  • Postman Collection (v2.1)
  • Swagger/OpenAPI (2.0, 3.0)
  • HAR
  • Apiguardian
  • YApi

Export:

  • OpenAPI 3.0
  • Swagger 2.0
  • Markdown
  • HTML
  • Apifox format

Keyboard Shortcuts

Common shortcuts:

  • Ctrl/Cmd + S: Save
  • Ctrl/Cmd + Enter: Send request
  • Ctrl/Cmd + B: Format JSON
  • Ctrl/Cmd + /: Comment/uncomment

Best Practices

  1. Clear naming: Interface names should clearly describe their function
  2. Complete documentation: Add descriptions for every parameter
  3. Logical grouping: Organize interfaces by module
  4. Use environments: Differentiate between development, testing, and production
  5. Write tests: Create automated tests for important interfaces
  6. Regular sync: Keep local and cloud data in sync