{"id":23185061,"url":"https://github.com/marketto/mockettaro","last_synced_at":"2025-08-18T15:32:46.173Z","repository":{"id":31025387,"uuid":"126546341","full_name":"Marketto/mockettaro","owner":"Marketto","description":"Node REST mock server","archived":false,"fork":false,"pushed_at":"2024-10-02T13:33:47.000Z","size":2976,"stargazers_count":1,"open_issues_count":17,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-16T07:47:36.901Z","etag":null,"topics":["command-line-tool","http-server","http-status-code","json-schema-validator","json-server","json-server-mock","mock-server","nodejs","npm-package","rest","rest-server"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Marketto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-23T22:51:22.000Z","updated_at":"2024-10-02T13:33:51.000Z","dependencies_parsed_at":"2023-01-14T18:11:36.582Z","dependency_job_id":null,"html_url":"https://github.com/Marketto/mockettaro","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketto%2Fmockettaro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketto%2Fmockettaro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketto%2Fmockettaro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marketto%2Fmockettaro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Marketto","download_url":"https://codeload.github.com/Marketto/mockettaro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230246746,"owners_count":18196411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line-tool","http-server","http-status-code","json-schema-validator","json-server","json-server-mock","mock-server","nodejs","npm-package","rest","rest-server"],"created_at":"2024-12-18T09:26:09.353Z","updated_at":"2024-12-18T09:26:10.029Z","avatar_url":"https://github.com/Marketto.png","language":"JavaScript","funding_links":["https://ko-fi.com/marketto"],"categories":[],"sub_categories":[],"readme":"# mockettaro\n\n[![NPM Version](http://img.shields.io/npm/v/mockettaro.svg?style=flat)](https://www.npmjs.org/package/mockettaro)\n[![NPM Downloads](https://img.shields.io/npm/dm/mockettaro.svg?style=flat)](https://npmcharts.com/compare/mockettaro?minimal=true)\n[![Dependency status](https://david-dm.org/Marketto/mockettaro.svg)](https://david-dm.org/Marketto/mockettaro)\n[![Dev dependency status](https://david-dm.org/Marketto/mockettaro/dev-status.svg)](https://david-dm.org/Marketto/mockettaro?type=dev)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FMarketto%2Fmockettaro.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FMarketto%2Fmockettaro?ref=badge_shield)\n[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=mockettaro\u0026metric=alert_status)](https://sonarcloud.io/dashboard/index/mockettaro)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=mockettaro\u0026metric=coverage)](https://sonarcloud.io/dashboard/index/mockettaro)\n[![Maintainability](https://sonarcloud.io/api/project_badges/measure?project=mockettaro\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard/index/mockettaro)\n[![Reliability](https://sonarcloud.io/api/project_badges/measure?project=mockettaro\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard/index/mockettaro)\n[![Build Status](http://ci.marketto.it/buildStatus/icon?job=Mockettaro)](http://ci.marketto.it/job/Mockettaro)\n[![LICENSE](https://img.shields.io/badge/licese-MIT-gold.svg)](https://github.com/Marketto/mockettaro/blob/master/LICENSE)\n[![Blog](https://img.shields.io/badge/blog-marketto-blue.svg)](http://blog.marketto.it)\n[![Buy me a coffee](https://img.shields.io/badge/Ko--fi-donate-blueviolet)](https://ko-fi.com/marketto)\n\nInstant Server for JSON and XML Mocks with support for REST structure, VERB specific or generic file mapping, schema for request validation and .config.yml files to specify response delay, HTTP status code and headers; supporting xml/json automatic conversion driven by Accept header\n\n## Upgrade warning\n\n- Config files .code and .delay are no longer supported by 2.0.0, please use .config.yml files\n- No default root resource. Read documentation below on upgrade from 1.3.1\n- Major implementation changes. Read documentation below on upgrade from 1.2.2\n\n## Supported files for mocks\n\n- **.json** =\u003e _resource_\n- **.xml** =\u003e _resource_\n- **.txt** =\u003e _resource_\n- **.config.yml** =\u003e _yaml config for custom status, delay and headers_\n- **.schema.json** =\u003e _request validator_\n\n## Supported responses\n\n- **JSON** =\u003e _Default_\n- **XML** =\u003e _\"Accept\"_: **_\"application/xml\"_**\n- **TXT** =\u003e _\"Accept\"_: **_\"text/plain\"_**\n\n## Supported config (.config.yml)\n\n- **status** _numeric_\n- **delay** _numeric_\n- **headers** _List of Key/Value_\n\n## Installation\n\n### Global\n\n#### npm\n\n```{r, engine='bash', dev_install}\nnpm i mockettaro -g\n```\n\n#### yarn\n\n```{r, engine='bash', dev_install}\nyarn global add mockettaro\n```\n\n### Project dependency\n\n#### npm\n\n```{r, engine='bash', dev_install}\nnpm i mockettaro --save-dev\n```\n\n#### yarn\n\n```{r, engine='bash', dev_install}\nyarn add mockettaro --dev\n```\n\n## Getting Started\n\n### Command line\n\n```{r, engine='bash', run}\nmockettaro\n```\n\nIt will serve the current working directory tree as a REST API (matching JSON files) on http://localhost:8080/\n\n### Nodejs Express\n\n```js\nconst express = require(\"express\");\nconst { mockettaro } = require(\"mockettaro\");\nconst logger = require(\"@marketto/js-logger\").global();\n\nconst app = express();\napp.use(\n\t\"/mocks\",\n\tmockettaro({\n\t\t//foldername to seek for folderTree / json or xml files\n\t\tdirectory: \"mocks\", //default: './'\n\t\t//Current working directory to use as a targed for the given directory\n\t\tcwd: __dirname, //default: process.cwd()\n\t\tresponseDelay: 1000, //default: 0\n\t\tcacheLifetime: 1000, //default: 3000\n\t\tverbose: false, //default\n\t\terrors: true, //default\n\t\tinfo: true, //default\n\t})\n);\n\nconst port = 3000;\napp.listen(port, () =\u003e {\n\tlogger.info(`Mockettaro test server running on  port ${port}`);\n});\n```\n\n## Command line overview\n\n### Version\n\nDisplay the current Mockettaro version\n\n```{r, engine='bash', run}\nmockettaro -v\n```\n\n### Port number\n\nMockettaro server will listen on the provided port\n\n```{r, engine='bash', run}\nmockettaro -p 1234\n```\n\n### URI Resource root path\n\nMockettaro will serve resources, using the provided path as the root\n\n```{r, engine='bash', run}\nmockettaro -r my-mock/resource\n```\n\n### Folder for static files\n\nMockettaro will load resources, matching the resource entry URI, fetching the provided local path\n\n```{r, engine='bash', run}\nmockettaro -f ./mocks/rest\n```\n\n### Delay in ms to provide responses\n\nMockettaro will serve resources waiting the delay ms before providing each positive response\n\n```{r, engine='bash', run}\nmockettaro -d 1500\n```\n\n### Cache Lifetime in ms\n\nMockettaro will cache HTTP codes and response bodies for the provided cache lifetime ms\n\n```{r, engine='bash', run}\nmockettaro -t 30000\n```\n\n### Silent\n\nDisable all logs except errors\n\n```{r, engine='bash', run}\nmockettaro -s\n```\n\n### Verbose\n\nDisplay all levels log messages\n\n```{r, engine='bash', run}\nmockettaro --verbose\n```\n\n## Managing Mocks\n\n### GUI - ServiceDesigner\n\nTo quickly design your RESTful services mocks/json schemas you can use [MK Service Designer](http://servicedesigner.marketto.it/), available also on [GitHub](https://github.com/Marketto/mkServiceDesigner), and export a Mockettaro package which would be ready to use.\n\n[Online Service Designer](http://servicedesigner.marketto.it/)\nOnce extracted, from the package folder, run from the command line:\n\n```{r, engine='bash', run}\nmockettaro\n```\n\n### Hello World\n\nCreate a folder with a file named test.GET.json which contains the following:\n\n```json\n{\n\t\"message\": \"Hello world!\"\n}\n```\n\nFrom the command line run:\n\n```{r, engine='bash', run}\nmockettaro\n```\n\ntry to visit http://localhost:8080/test\n\n### RESTful services Mocks\n\nConsider you have a /customer API which provide a list @ /customer and details @ /customer/{uid}\nIn your Mock folder (anywhere) create the following folder structure:\n\n```\n/\n├── customer\n│   ├── foo.GET.json\n│   ├── foo.GET.delay\n│   ├── default.PUT.schema.json\n│   ├── default.PUT.json\n│   ├── foo.DELETE.config.yml\n│   └── default.GET.json\n├── customer.POST.schema.json\n├── customer.POST.json\n├── customer.POST.config.yml\n└── customer.GET.json\n```\n\n#### customer.GET.json\n\n```json\n{\n\t\"data\": [\n\t\t{\n\t\t\t\"uid\": \"foo\",\n\t\t\t\"name\": \"Bar Foo\"\n\t\t},\n\t\t{\n\t\t\t\"uid\": \"smith\",\n\t\t\t\"name\": \"John Smith\"\n\t\t}\n\t]\n}\n```\n\n#### customer/foo.GET.json\n\n```json\n{\n\t\"data\": {\n\t\t\"uid\": \"foo\",\n\t\t\"name\": \"Bar Foo\"\n\t}\n}\n```\n\n#### customer/foo.GET.delay\n\nDelay in milliseconds for the matching resource\n\n```text\n500\n```\n\n#### customer/default.GET.json\n\n```json\n{\n\t\"data\": {\n\t\t\"uid\": \"smith\",\n\t\t\"name\": \"John Smith\"\n\t}\n}\n```\n\n#### customer/foo.PUT.json\n\n```json\n{}\n```\n\n#### customer/default.PUT.schema.json\n\nAll PUT request to /customer/xxxx will be validated against it!\n\n```json\n{\n\t\"$schema\": \"http://json-schema.org/schema#\",\n\t\"properties\": {\n\t\t\"firstName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"minLength\": 3\n\t\t},\n\t\t\"lastName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"minLength\": 3\n\t\t},\n\t\t\"birthDate\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"minLength\": 10,\n\t\t\t\"format\": \"date-time\"\n\t\t},\n\t\t\"gender\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [\"M\", \"F\"]\n\t\t}\n\t},\n\t\"title\": \"customer/{uid}\"\n}\n```\n\n#### customer/foo.DELETE.config.yml\n\nConfig to return custom code and/or delay and/or headers in response for the matching resource\n\n```yaml\nstatus: 204\n#delay: 0\nheaders:\n  test-header: Mockettaro\n```\n\n#### customer.POST.schema.json\n\nAll POST request to /customer will be validated against it!\n\n```json\n{\n\t\"$schema\": \"http://json-schema.org/schema#\",\n\t\"properties\": {\n\t\t\"firstName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"minLength\": 3\n\t\t},\n\t\t\"lastName\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"minLength\": 3\n\t\t},\n\t\t\"birthDate\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"minLength\": 10,\n\t\t\t\"format\": \"date-time\"\n\t\t},\n\t\t\"gender\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [\"M\", \"F\"]\n\t\t}\n\t},\n\t\"required\": [\"firstName\", \"lastName\"],\n\t\"title\": \"customer\"\n}\n```\n\n#### customer.POST.config.yml\n\nAll POST request to /customer , if passing validation, will have a response with the provided HTTP status code\n\n```yaml\nstatus: 201 # Response status code\n#delay: 0 # Response delay in ms\n#headers: # list of headers\n#   test-header: Mockettaro # custom header\n```\n\n#### customer.POST.json\n\nAll POST request to /customer , if passing validation, will have a response with the following HTTP body\n\n```json\n{\n\t\"uid\": \"newCustomer\"\n}\n```\n\n#### Run mock server\n\n##### Global\n\n```{r, engine='bash', run}\nmockettaro -r services\n```\n\n##### NPX\n\n```{r, engine='bash', run}\nnpx mockettaro -r services\n```\n\n#### URL to test\n\n- http://localhost:8080/services/customer GET, POST\n- http://localhost:8080/services/customer/foo GET, PUT, DELETE\n- http://localhost:8080/services/customer/smith GET, PUT\n- http://localhost:8080/services/customer/anything GET, PUT\n\n## Changelog\n\n### 2.1.2\n\n- Added default Access-Control-Allow-Headers and Access-Control-Allow-Methods Headers to \\*\n\n### 2.1.1\n\n- Added default Access-Control-Allow-Origin Header to \\*\n\n### 2.1.0\n\n- Added support for txt (text/plain) files\n\n### 2.0.0\n\n- Introduced config.yml files for custom settings\n- Added support for custom HTTP status code in config.yml files\n- Added support for custom responde delay in config.yml files\n- Added support for custom headers in config.yml files\n- Removed support for .code files\n- Removed support for .delay files\n\n### 1.4.4\n\n- Fixed min port number: 80\n- Increased test coverage over classes (error handling focused)\n\n### 1.4.3\n\n- Fixed delay parameter bug\n- Fixed resource delay cache bug\n- Package json scripts now use npx\n- Tests and coverage use only nyc and mocha\n- Mocha and Nyc config/parameters moved to test/mocha.opts and .nycrc.json\n- jsdoc comments review\n- Increased test coverage over classes (error handling focused)\n\n### 1.4.2\n\n- Improved performance implementing iterators\n- Implemented xml support for mocks\n- Implemented dynamic response conversion to json or xml depending on request Accept type (JSON default)\n- Improved unit tests to ensure they are independent from others\n\n### 1.4.1\n\n- Sonar config to exclude docs from coverage\n\n### 1.4.0\n\n- Docs\n\n### 1.3.12\n\n- Used standard paths for bin and lib\n- Fixed default params for MockettaroProgram\n- Divided tests per class\n- Added bin Unit\n- Added separate unit test to prevent cache test issues\n\n### 1.3.11\n\n- Minor fixes\n- Completed jsdoc\n\n### 1.3.10\n\n- Fixed missing args for MockettaroProgram\n\n### 1.3.9\n\n- Fixed typo in dependency\n\n### 1.3.8\n\n- Arg Number Parser moved as static method\n- Added more tests\n- Removed deprecated code\n\n### 1.3.7\n\n- Implemented MockettaroProgram.parser and MIN, MAX and DEFAULT constants\n- Implemented MockettaroProgram.parser tests for parsing and setting MIN, MAX or DEFAULTS\n\n### 1.3.6\n\n- Fixed Resource RegExp\n- Path and resource RegExps moved as static property in MockettaroProgram\n- Added unit tests for Path and Resource regexps\n- Added test for corrupted json mock reading\n\n### 1.3.5\n\n- Fully migrated to ES6\n- Command line logics moved to MockettaroProgram class\n- MockettaroProgram covered by tests\n- Added -s / --silent and --verbose for silent and verbose mode\n\n### 1.3.4\n\n- Fixed Error Handler\n- Mockettaro core refactored as an ES6 Class\n- Fixed working directory issue\n- Implemented cwd in mockettaro\n- Updated test and debug config to pass cwd\n\n### 1.3.3\n\n- Removed all unused dependencies\n- Removed logger and chalk dependency\n- Used @marketto/js-logger to log event on console\n- Removed 'use strict' since it's moving to ES6\n\n### 1.3.2\n\n- Log info on missing and found json\n- Fixed compatibility issues with Windows\n- Updated example expressUse.json implementation\n- Added launch.json for development purpose\n\n### 1.3.1\n\n- Info logger level is true bny default\n- Warning logger level is on for debbugging purpose\n- Improved compatibility with trailing slash api\n\n### 1.3.0\n\n- Core reworked in classes ES6\n- Command Line property -f --folder added\n- Removed server method, import the lib as { mockettaro } and use it like mockettaro()\n- Mockettaro router accept only an object of optional params in input {directory, responseDelay, cacheLifetime, verbose, errors }\n- Provided logger micro-logging embedded utility\n\n## LICENSE\n\n[MIT License](LICENSE)\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FMarketto%2Fmockettaro.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FMarketto%2Fmockettaro?ref=badge_large)\n\n## AUTHOR\n\n[Marco Ricupero](mailto:marco.ricupero@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarketto%2Fmockettaro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarketto%2Fmockettaro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarketto%2Fmockettaro/lists"}