Easymock
An easy way to mock an api using node
Install / Use
/learn @opedro/EasymockREADME
easymock
An easy way to mock an api using node
Getting Started
git clone https://github.com/opedro/easymock.git
npm install
node easymock.js
Prerequisites
You only need Node js to run Easymock
How to use
The project gives you a folder called "mocks", in it you'll find examples of mocks that you can edit as you wish. Every "*.esm" file on the "mocks" folder will be read and each one of them will become an interface on your host.
Example: ex1.esm
{
"method": "get",
"success":"{'errorCode': '0', 'amigos': [{'nome': 'Macito', 'idade': '22'}]}",
"fail": "{'errorCode': '1', 'errorMessage': 'exemplo'}",
"failChance": "20"
}
This esm file will provide a server on locahost/ex1 with "{'errorCode': '0', 'amigos': [{'nome': 'Pavanelli', 'idade': '23'}]}" as the response 80% of the time (based on the "failChance" parameter). 20% of times the response will be "{'errorCode': '1', 'errorMessage': 'exemplo'}", of course.
ex3.esm
{
"method": "post",
"parameters": [{"name": "login", "expect": "correto"},
{"name": "password", "expect": "12345678"}
],
"success":"{'errorCode': '0', 'perfil': [{'nome': 'Jonas', 'token': 'asd564a&5d56sa%dsa54$a5s64d'}]}",
"fail": "{'errorCode': '1', 'errorMessage': 'exemplo'}",
"failChance": "10"
}
This esm file will provide a server on localhost/ex3 with "{'errorCode': '0', 'perfil': [{'nome': 'Jonas', 'token': 'asd564a&5d56sa%dsa54$a5s64d'}]}" as the response ONLY WHEN the body was "{"login": "correto", "password":"1234565645478"}". Any incorrect data will make the return to be "{'errorCode': '1', 'errorMessage': 'exemplo'}". obs: The correct body will still fail 10% of the times.
Authors
- Pedro Ruiz - Initial work - opedro
I deserve a coffee
Donate R$ 3,00 https://bit.ly/2u5e6Wn
Related Skills
node-connect
342.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
85.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
342.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
