1.0.3 • Published 8 years ago
anymocker v1.0.3
anymocker
A smart mock server based on Anyproxy, can install by typing
npm install anymocker -gThis illustrate below show how it works:

Before all
this is a tool using for fine tuning API json response, which based on Anyproxy, so please follow up anyproxy instruction to setup the environment, that's the basis of rules
use jsonpath to locate a field in API response
Rule detail
here are some examples about defining a rule
- replace all API's response(json format), make all
namefield equal togithub, alltextfield equal toanymocker, that's a global rule
$ anymocker -s save -m $..name=github $..text=anymocker- replace api
xxx/xxxresponse(json format), make allnamefield equal togithub, delete all thetextfield, and then inject a fieldtitle, valueddevil, that's a api rule
$ anymocker -s save -a xxx/xxx -m $..name=github -d $..text -i $.title=devil- when both api and global rules are specified, should notice that for the same field, api will override global, below the api
xxx/xxxwill mocktextfield asgithub, and for other request(global) will mocktextfield asgitlab
$ anymocker -s save -a xxx/xxx -m $..name=github -d $..text -i $.title=devil -m $..name=gitlabFuzzy
if you don't want to fake data so painful, you can just put a FUZZ as the value
- only number, string and boolean can be fuzzy
- can randomly return null
- for number, there are chances to amplify and shrink by multiple
- for string, there are chances to get an empty ''
$ anymocker -s save -a xxx/xxx -m $..name=FUZZ -d $..text -i $.title=devil -m $..name=gitlab $..text=FUZZTODO
for multi apis mock, something need to consider:
if input parameters are like this:
$ anymocker -s save -a api1 -m x -a api2 -m y -i zyou intend to make rules below:
{
"api": {
"api1": {
"mock": [
x
]
},
"api2": {
"mock": [
y
],
"inject": [
z
]
}
}
}but unfortunately, what you get exactly is:
{
"api": {
"api1": {
"mock": [
x
],
"inject": [
z
]
},
"api2": {
"mock": [
y
]
}
}
}the latter -i z will be squashed as an api1 rule, that's because anymocker analisis parameters by order.
so please, to set a parameter at a prior place, or you just want to make it easy, try anymocker -s save -a api1 -m x -i -a api2 -m y -i z