{"id":22311736,"url":"https://github.com/saturate/mock-api-middleware","last_synced_at":"2025-07-29T08:32:34.521Z","repository":{"id":57300000,"uuid":"71333751","full_name":"Saturate/mock-api-middleware","owner":"Saturate","description":"Middleware for NodeJS, BrowserSync ect. for creating API Mock's fast.","archived":false,"fork":false,"pushed_at":"2025-06-03T12:55:25.000Z","size":20,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-01T03:04:55.366Z","etag":null,"topics":["browsersync","json","middleware","mocking","nodejs"],"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/Saturate.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":"2016-10-19T08:08:17.000Z","updated_at":"2025-06-03T12:55:26.000Z","dependencies_parsed_at":"2022-09-01T08:40:55.811Z","dependency_job_id":null,"html_url":"https://github.com/Saturate/mock-api-middleware","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Saturate/mock-api-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saturate%2Fmock-api-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saturate%2Fmock-api-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saturate%2Fmock-api-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saturate%2Fmock-api-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Saturate","download_url":"https://codeload.github.com/Saturate/mock-api-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saturate%2Fmock-api-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267653273,"owners_count":24122172,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["browsersync","json","middleware","mocking","nodejs"],"created_at":"2024-12-03T21:27:15.080Z","updated_at":"2025-07-29T08:32:34.510Z","avatar_url":"https://github.com/Saturate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mock-api-middleware\n[![npm version](https://img.shields.io/npm/v/mock-api-middleware.svg?style=flat-square)](http://npmjs.org/mock-api-middleware)\n[![npm downloads](https://img.shields.io/npm/dm/mock-api-middleware.svg?style=flat-square)](http://npmjs.org/mock-api-middleware)\n[![License](https://img.shields.io/npm/l/mock-api-middleware.svg?style=flat-square)](https://github.com/Saturate/mock-api-middleware/blob/master/LICENSE)\n\nMiddleware for NodeJS, BrowserSync ect. for creating API Mock's fast.\nYou can shorten it MAM, like the sound you say when food is delicious.\n\n## Installation\n\n`npm install --save-dev mock-api-middleware`\n\n## Usage\n\n`mam(route, [options])`\n\n### Use with BrowserSync\n```javascript\n\nconst mam = require('mock-api-middleware');\n\n// You could put this directly in the middleware array of browserSync\nconst mockApi = mam('/mockapi', { // \u003c--- Route where to mount the API\n\tmockPath: './mocks/' // \u003c--- Where to find the API files\n});\n\nbrowserSync.init({\n\tserver: './dist',\n\tmiddleware: [\n\t\tmockApi // \u003c--- Just put it here like anyother middleware\n\t]\n});\n```\n## Options\n\nThis module accepts the following options\n\n- **mockPath**: Path to mock files\n- **dataset**: Override datasets with this, accepts an object. Will only override if the sames keys are defined.\n- **helpers**: Your own helpers which are described in \"[writing-your-own-helpers](https://github.com/webroo/dummy-json#writing-your-own-helpers)\" of [dummy-json](https://github.com/webroo/dummy-json)\n\n## Mocking\nTo mock an API or a service. All you need is a folder and some files.\n\n```\nmocks\n│   users.GET.json\n└───users\n│       │   _.GET.json\n│       │   admin.GET.json\n│       │   ...\n│\n│   products.GET.json\n└───products\n        │   theonlyproduct.GET.json\n```\n\nThe latter folder example would create an API with endpoints like this:\n\n`/mockapi/users`   \n`/mockapi/users/admin`   \n`/mockapi/users/*`   \n`/mockapi/products`   \n`/mockapi/products/theonlyproduct`   \n\nThe only magic thing about this is the `_.GET.json` this is a CATCH-ALL that will be a fallback for all \"missing files\" in the current folder.\n\n### Generate JSON\nAnother smart trick is that you can generate JSON.\nThis enables you to make a list of users fast without typing all the data yourself.\n\nFor more information head over to the [dummy-json](https://github.com/webroo/dummy-json) repo. MAM uses this under the hood with some extentions and modifications.\n\n\u003ctable width=\"100%\"\u003e\n\u003cthead\u003e\u003ctr\u003e\u003ctd width=\"50%\"\u003eTemplate string\u003c/td\u003e\u003ctd width=\"50%\"\u003eOutput string\u003c/td\u003e\u003c/tr\u003e\u003c/thead\u003e\n\u003ctbody\u003e\u003ctr\u003e\u003ctd align=\"left\" valign=\"top\"\u003e\n\u003cpre style=\"padding: 0\"\u003e\n{\n  \"users\": [\n    {{#repeat 2}}\n    {\n      \"id\": {{@index}},\n      \"name\": \"{{firstName}} {{lastName}}\",\n      \"email\": \"{{email}}\"\n    }\n    {{/repeat}}\n  ]\n}\n\u003c/pre\u003e\n\u003c/td\u003e\u003ctd align=\"left\" valign=\"top\"\u003e\n\u003cpre style=\"padding: 0\"\u003e\n{\n  \"users\": [\n    {\n      \"id\": 0,\n      \"name\": \"Allan Kimmer Jensen\",\n      \"email\": \"allankimmerjensen@example.com\"\n    },\n\t{\n      \"id\": 1,\n      \"name\": \"John Doe\",\n      \"email\": \"john.doe@nsa.gov\"\n    }\n  ]\n}\n\u003c/pre\u003e\n\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaturate%2Fmock-api-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaturate%2Fmock-api-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaturate%2Fmock-api-middleware/lists"}