whistle.mockya
v0.4.2
Published
API mock plugin for whistle
Downloads
49
Readme
whistle.mockya
A rule-based API Data Mock plugin built on whistle.
Usage
Install & Start whistle
npm i -g whistle
w2 start
Install whistle.mockya
w2 install whistle.mockya
Proxy your website
Use tools like SwitchyOmega to proxy your website to whistle
Add rule in whistle's Rules tab
[your_api_prefix] mockya://[mockya_collection_id]
# for example
http://mockya.test/api mockya://test
Open whistle.mockya to add mock data
Visit http://localhost:8899/whistle.mockya (replace port with your own one) and install as PWA (recommended)
Features
Group your mock data in collections
Match request by url path & key-value pair in query/body
Auto switch mock data based on rules
Support JSON5 & JavaScript & Mock.js
You can compose your mock data in both JSON5 and JavaScript, along with Mock.js syntax.
Customize response delay
Useful when you need to test things like loading state UI.
Encode your data on demand
MockYa has special 'command' syntax to encode specific value in json.
// append '>[command]' to some field
{ "key>[command]": xxx }
// for example
{ "data>encode": { "a": 1 } }
// will return
{ "data": "{\"a\":1}" }
Currently support:
| Command | Description |
| ------- | ------------------------------------------ |
| encode | use JSON.stringify
to encode field value |