smocker
/
2.2.1
smocker 2.2.1
Install from the command line:
Learn more about npm packages
$ npm install @kitabisa/smocker@2.2.1
Install via package.json:
"@kitabisa/smocker": "2.2.1"
About this version
CLI tools for serve supple mock server with random fake data using Faker.js
- Using Bun
- Using Express.js for API routes
- Written in Typescript
- Random fake data using Faker.js
- Schema validation using JSON Schema
- Flexible on-demand response (can modify body, status, headers, and delayed response)
- No data storage needed
Setup smocker
$ npm install --global @kitabisa/smocker
Running mock with default params
$ ktbs-smocker
Running mock with custom params
$ ktbs-smocker \
--port 3000 \
--secret "mysecret" \
--allowOrigin "*.kitabisa.com,*.kitajaga.id" \
--allowMethods "GET,POST,PATCH" \
--allowHeaders "Content-Type,Authorization"
See a list of all available options
$ ktbs-smocker --help
See a installed version
$ ktbs-smocker --version
Specify a search body param to retrieve a response with that body.
GET http://localhost:8080/?mock\[response\]\[body\]={"ping":"pong"}
HTTP/1.1 200 OK
content-type: application/json
content-length: 15
{"ping":"pong"}
Specify a search status param get back that code status. The status must be inside the range 200 to 599.
GET http://localhost:8080/?mock\[response\]\[status\]=301
HTTP/1.1 301 Moved Permanently
content-type: application/json
content-length: 0
Specify a search header param as json string to get them back.
GET http://localhost:8080/?mock\[response\]\[headers\]={"x-hello":"world"}
HTTP/1.1 200 OK
x-hello: world
content-length: 0
Specify a search delay param in milliseconds in order to delay the response.
GET http://localhost:8080/?mock\[response\]\[delay\]=3000
Specify a search schema validation in json schema (stringify) to set request body validations.
GET http://localhost:8080/?mock\[request\]\[body\]\[schema\]=${{ stringify json schema }}