Logo

Mastering EazyMock: Advanced Rules Feature Guide - Part 2

In this guide, we'll explore the advanced rules feature of Mock APIs, empowering users to create multiple responses with distinct rules for precise testing

avatar
Dat TranPublished on January 19, 2024
loading

In the dynamic world of software development, testing and prototyping APIs play a crucial role. Mock APIs are invaluable tools that allow developers to simulate real API responses, ensuring a seamless integration process. In this guide, we'll explore the advanced rules feature of EazyMock, empowering users to create multiple responses with distinct rules for precise testing scenarios.

Why Advanced Rules Matter

EazyMock are not just about simulating generic responses; they are about replicating the complexity of real-world APIs. With the advanced rules feature, users can define specific conditions for different parts of the API request, including the body, query parameters, headers, and path.

Getting Started

1. Creating an EazyMock API

Begin by creating a new EazyMock API. Most platforms provide a user-friendly interface for this. Once your API is set up, you'll notice an option for advanced rules.
The process of creating a EazyMock API is outlined in this blog.

2. Setting Rules for Body, Query, Header, and Path

In this sample we together find out how to use rules to create multi-response with a single API by EazyMock

1. POST API where user can post article and filter by region ----- Using body rules
2. GET API where user can get list TOP article by age ---- Using query rules
3. GET API where use can get article via pages number ---- Using path rules

Body Rules

Users have the flexibility to generate two distinct responses: one tailored for the "Asia region" and another for the "America region." This involves creating two unique request bodies to align with each response.

Asia America
img img

Subsequently, when utilizing API testing tools, we can verify that the responses correspond appropriately to the distinct requests.

Asia America
img img

Query rules

By defining two query rules, users can obtain two distinct responses.

/?age=20 for 1 response 
/?age=30 for another response
  • Mock Detail
Age 20 Age 30
img img
  • By utilizing cURL copy, users have the option to select which response they want to run.

img

  • Response
Age 20 Age 30
img img

Header rules

  • Header rules are analogous to the previously explained query rules.

Path rules

  • Similar to the query and header rules, the configuration process in the rule tab is comparable. However, users need to adhere to a specific URL format to activate path rules. the URL for the path must be:
/:path_id

example: 
GET /article/pages/:page_id

img

Subsequently, users can obtain a response following the specified path format.

Page 1 Page 2
img img
0
1
409
share post

Comments

avatar