Background usualy when we develop a new feature on website or miniprogram or mobile application, we go through 3 steps: 1. design api documents,include api path,paramter,response; 2. develop frontend and backend at the same time; 3. testing and debugging the frontend and backend program.
in step 2, the frontend need to mock the api??s parameter and response,to debug program,and if there??s multiple front-end applications,each app need to do mock. consider this scenario,if our api gateway can support api mocking,the steps 2 will come down to: 1. turn on mocking plugin when backend is still developing apis. 2. turn off mocking plugin when the api is finished. and there is nothing need to do for frontend developer,even neednt to change the api url. based on the above scenario, the mocking plugin can be use in more scenario,such as: when we pressure test the APISIX. we can use the mocking plugins to mock duration of api and status and response,instead of real upstream. in microservice invocation chain,we can mock service one by one to find the abnormal service. Plugin Design this plugin design is reference to mock.js and kong's mocking plugin. it is planned to be implemented in two phases. phase 1, goal to implement base mock abilities. the general design is as follows: local schema = { type = "object", properties = { -- specify response delay time,default 0ms delay = { type = "integer" }, -- specify response status,default 200 response_status = { type = "integer" }, -- specify response content type,support application/xml,text/plain and application/json,default application/json content_type = { type = "content_type" }, -- specify response body. response_example = {type = "string"}, -- specify response json schema,if response_example is not nil,this conf will be ignore. -- generate random response by json schema. response_schema = { type = "object" }, }, anyOf = { {required = {"response_example"}}, {required = {"response_schema"}} } } phase 2, goal to implement higher-order ability,such as "expectation and response patterns".