- Syvizo API Management Platform
- Overview
- Getting Started
- Manage Users and Accesses
- Design APIs
- Publish API
- Collaborate
- Validate APIs
- Manage API Flows
- Flow Management
- API Flow Manager
- Policies
- Traffic Management
- Security
- Transformation
- Extension
- Insights
Setting up Mock Data
Syvizo platform provides mock capabilities so you can interface your APIs with systems that may not be fully functional or available yet. The following examples illustrate when mocking can be useful:
- You're working on a frontend that will 'plug in' to an API backend that is not available yet.
- You're looking to learn the structure of an API but are not picky about the data yet.
- You do not want to actually make calls to backend APIs and still want continue developing your front end that depends on the responses from certain APIs
Mocking APIs is a useful and faster way of development of system that use APIs. Many developers find it useful to mock dependencies rather than waiting for the APIs to be fully developed or spinning up actual duplicates of resources. On a high-level, a mock API means that you have a service that returns close to real data, which in turn is based on a real API.
A mock API is an API that responds data just like you would expect a real API to do, however it only focuses on replicating the data returned, not the inner logic that’s used to calculate the data. This is extremely useful in many cases, like when you’re using a third-party API that is rate-limited. Or, when the API you rely on isn’t fully developed yet.
Initial Development of APIs
During the initial development of your APIs you may be lucky enough that all of your dependencies are third-party services, in which case a mock API can still be useful. However, mock APIs are an incredibly strong tool in the cases where you are multiple teams making APIs that depend on each other.
Suppose your teams are working on a new webstore. Team X starts working on the backend for the webstore, while team Y is working on the frontend. Team Y can start working on the design of the user interface items.
However, there would be certain parts of the user interface that will depend on the backend APIs such as product page. Team X has only just started working on the backend API, so team Y can not use the actual backend to get the products.
In this scenario, as part of the planning there must be the design of the APIs done and created in the API Design Studio. This means the teams know exactly what the data from the backend will look like, once the API design is done, both teams can start working in parallel and Team Y just needs to use the mock data to make sure that the frontend can handle the data.
To create mock data for a method, click on the "Mock Data Setup" button:
You will be taken to the screen to manage mock data.
To create or manage the mock data for any method select the method from the left menu that shows the path and method structure of the API.
The right side panel will show any available mock data setups.
Specific mock data
This means that the mock data is created specifically for a condition in the request. For example, if you want to return a response if userid field in the request is “uid001”, then you can setup the mock data to do so.
Click "Add Specific" on button, this will open the dialog box for adding specific response.
The left most panel shows a tree structure that represent request json. Expand by clicking on the element to reach to the field for which you want to setup the condition in request. Click on the field and then specify its value in “Identifying Value” field. Paste or type the response that should be returned.
Click on OK and save by clicking the button on right top of the screen.
Any request call made to the mock service and satisfies this condition for the setup field and value will return the response that is set up.
If multiple matches are found, then the response for the first match is returned.
Random mock data
Random mock data is the data that is generated randomly but conforms to the type that is setup. The values setup are random generated and returned in the response and does not depend on the request data.
For example, if there is a field that should return an email address, then it can be setup as such and for every response for the request the field will be filled by a randomly generated email address.
The types that are available are: Name, Full Name, Email, Address
The generic types that can be setup are:
String: This is a string of text
Number String: This is text string that contains only numbers.
Integer: Random integer value
Decimal Number: Random decimal number value
The configurations for types “String” and “Number String” are:
- Minimum Length: Minimum number of characters in text string
- Maximum Length: Maximum number of characters in text string
- Prefix: Text that needs to be added to the text string before it. This will be additional to the minimum or maximum length specified
- Suffix: Text that needs to be added to the text string after it. This will be additional to the minimum or maximum length specified
The configurations for Integer and Decimal Number types are:
- Minimum Value
- Maximum Value
To configure random mock data, click on "Add Random" button.
In the dialog box that opens, the left most panel shows a tree structure that represent response json. Expand by clicking on the element to reach to the field for which you want to setup the random value to be generated. Click on the field and then specify its type from the drop down box. In case of generic types, the additional configurations can be specified.
Click on OK and save by clicking the button on right top of the screen.
Do note that in case of both specific and random configurations match for any request, the specific configuration will take preference.