Online API Mocking Tools Comparison: Postman vs Apidog
API Mock is a commonly used feature for developers when building APIs. Both Postman and Apidog support API Mock. Let's take a look at the differences in functionality between these two products.
API Mock is a commonly used feature by developers when building APIs. In the early stages of software development, the backend API interfaces may not have been implemented or may not have been fully implemented. In such cases, Mock API can simulate the behavior of the backend API for front-end developers to call, thus avoiding the need to wait for the completion of the backend API.
Both Postman and Apidog support API Mock, and this article introduces the differences in their features through three scenarios.
Scenario 1. Fixed Mock Values
We use the user detail interface as an example to demonstrate fixed return values. The interface is defined as follows:
- Request method: GET.
- URL: /api/user/{id}. Where {id} is a parameter representing user ID.
- Response type: json,
- Response content:
{
id: number, // user ID
name: string, // username
avatar: string, // avatar image URL
}
The fixed response content is as follows:
{
"id": 1,
"name": "Jane,
"avatar": "http://dummyimage.com/100x100",
}
Postman Implementation
A Mock needs to be created in Mock Server in Postman.
Now, let's test the effect. Under Collections, you can find the created Mock. Click the Send button and you will get the following:
Apidog Implementation
Apidog automatically creates Mock when creating an interface. Let's create an interface below.
Apidog generates Mock values randomly based on the structure of the response information by default. To generate fixed values consistent with the response example, simply change the Mock mode to response example priority in the project settings.
Next, click the Quick Request in the Mock section of the interface details. You can see the effect on the Quick Request page that opens.
Scenario 2: Random Mock Values
Sometimes we expect the interface to return random values. Postman does not support random Mock values, but Apidog does.
Apidog Implementation:
Change the Mock mode back to intelligent Mock priority in the project settings.
Let's take a look at the effect:
Random values are returned, but the Mock of the "name" field is a random string, which looks unpleasant. Let's change the Mock rule of the "name" field to return random names.
The result is like this:
Scenario 3: Return Different Values for Different Situations
We want to mock exceptional cases. For example, when the ID is 999, there is a response error.
{
"error": 1,
"errorMsg": "User information not found"
}
Postman Completion
Add an example to return an exceptional response under the Mock interface.
Test it now.
Apidog Completion
Expectations in Apidog's Advanced Mock, which enables this functionality.
Test it.
Conclusion
Through the above scenarios, we can see that although Postman and Apidog both support API Mock, Apidog's functionality is more powerful and easier to use. For those who have not used it, give Apidog a try.