{"id":51119003,"url":"https://github.com/sulthonzh/local-mock-api-factory","last_synced_at":"2026-06-25T00:30:36.763Z","repository":{"id":365507132,"uuid":"1266938084","full_name":"sulthonzh/local-mock-api-factory","owner":"sulthonzh","description":"Spin up mock REST APIs from a JSON file. Zero dependencies, zero config.","archived":false,"fork":false,"pushed_at":"2026-06-17T15:50:32.000Z","size":14,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-17T17:31:29.321Z","etag":null,"topics":["api","fake","local","mock","prototype","rest","testing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sulthonzh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-12T04:48:51.000Z","updated_at":"2026-06-17T15:52:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sulthonzh/local-mock-api-factory","commit_stats":null,"previous_names":["sulthonzh/local-mock-api-factory"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/sulthonzh/local-mock-api-factory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Flocal-mock-api-factory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Flocal-mock-api-factory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Flocal-mock-api-factory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Flocal-mock-api-factory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sulthonzh","download_url":"https://codeload.github.com/sulthonzh/local-mock-api-factory/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sulthonzh%2Flocal-mock-api-factory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34755061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"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":["api","fake","local","mock","prototype","rest","testing"],"created_at":"2026-06-25T00:30:36.685Z","updated_at":"2026-06-25T00:30:36.751Z","avatar_url":"https://github.com/sulthonzh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# local-mock-api-factory\n\n\u003e **⚠️ DEPRECATED - CRITICAL SECURITY VULNERABILITY**\n\u003e\n\u003e This project contains a critical security vulnerability and is deprecated. Please use [msw](https://github.com/mswjs/msw), [json-server](https://github.com/typicode/json-server), or [MirageJS](https://miragejs.com/) instead.\n\u003e\n\u003e **Security Issue:** The `_eval` feature uses `new Function()` for arbitrary code execution, which enables remote code injection attacks if used in production or shared environments. This vulnerability cannot be fixed without a complete redesign.\n\u003e\n\u003e **Deprecation Date:** June 23, 2026\n\n---\n\n\u003e Spin up a mock REST API from a JSON file. Zero dependencies, zero config.\n\nBecause you shouldn't have to set up Express, write boilerplate, or install a heavy framework just to fake an API for your frontend.\n\n## What it does\n\nYou write a JSON file describing your endpoints. This tool gives you a running server with those routes in about 2 seconds. That's it.\n\nNo Express, no Fastify, no plugins, no config files. Just Node's built-in HTTP server and a JSON definition.\n\n## Install\n\n```bash\nnpm install -g local-mock-api-factory\n```\n\nOr run without installing:\n\n```bash\nnpx local-mock-api-factory ./api.json\n```\n\n## Quick Start\n\nCreate `api.json`:\n\n```json\n{\n  \"port\": 3456,\n  \"routes\": {\n    \"/users\": {\n      \"get\": {\n        \"status\": 200,\n        \"body\": [\n          { \"id\": 1, \"name\": \"Ada Lovelace\" },\n          { \"id\": 2, \"name\": \"Alan Turing\" }\n        ]\n      },\n      \"post\": {\n        \"status\": 201,\n        \"body\": { \"ok\": true }\n      }\n    },\n    \"/users/:id\": {\n      \"get\": {\n        \"status\": 200,\n        \"body\": { \"id\": 1, \"name\": \"Ada Lovelace\" }\n      }\n    },\n    \"/health\": {\n      \"get\": {\n        \"status\": 200,\n        \"body\": {\n          \"status\": \"ok\",\n          \"timestamp\": { \"_eval\": \"new Date().toISOString()\" }\n        }\n      }\n    }\n  }\n}\n```\n\nRun it:\n\n```bash\nmockapi ./api.json\n```\n\nNow hit your endpoints:\n\n```bash\ncurl http://localhost:3456/users\ncurl http://localhost:3456/users/1\ncurl http://localhost:3456/health\n```\n\n## Features\n\n### Route params\n\nUse `:param` in paths — matched values are available in `_eval` expressions:\n\n```json\n\"/users/:id\": {\n  \"get\": {\n    \"status\": 200,\n    \"body\": {\n      \"_eval\": \"{ id: parseInt(params.id), name: 'User ' + params.id }\"\n    }\n  }\n}\n```\n\n### Dynamic responses with `_eval`\n\nGenerate timestamps, computed values, whatever JS can do:\n\n```json\n{\n  \"timestamp\": { \"_eval\": \"new Date().toISOString()\" },\n  \"count\": { \"_eval\": \"Math.floor(Math.random() * 100)\" }\n}\n```\n\n### Simulated latency\n\nAdd `delay` in milliseconds to simulate slow APIs:\n\n```json\n\"/heavy-data\": {\n  \"get\": {\n    \"status\": 200,\n    \"delay\": 2000,\n    \"body\": { \"data\": \"took a while, huh?\" }\n  }\n}\n```\n\n### Serve from file\n\nLoad response body from a separate JSON file:\n\n```json\n\"/catalog\": {\n  \"get\": {\n    \"status\": 200,\n    \"body\": { \"_file\": \"./data/catalog.json\" }\n  }\n}\n```\n\n### CORS\n\nCORS headers are on by default (`Access-Control-Allow-Origin: *`). Disable with `\"cors\": false`.\n\n### Auto 404\n\nAny path not defined in your routes returns a clean 404:\n\n```json\n{ \"error\": \"Not found\", \"path\": \"/unknown\", \"method\": \"GET\" }\n```\n\n## Why another mock tool?\n\nHonestly, most mock API tools are overengineered. They need config files, proxy setups, or a whole DSL. I just wanted something where I write a JSON file and get a server. No deps, no fuss.\n\nUse cases:\n- **Frontend prototyping** — build UI before the real API exists\n- **Testing** — consistent, predictable responses for integration tests\n- **Demos** — realistic-ish API without standing up a backend\n- **Workshops** — give participants a working API in seconds\n\n## CLI\n\n```bash\nmockapi \u003cdefinition.json\u003e [--port 8080]\n```\n\n| Flag        | Description                          |\n|-------------|--------------------------------------|\n| `--port, -p`| Override port (default: 3456)        |\n| `--help, -h`| Show help                            |\n\n## Programmatic API\n\n```javascript\nconst { start, createServer } = require('local-mock-api-factory');\n\n// Start a server\nconst server = await start('./api.json', { port: 4000 });\n// ... later\nserver.close();\n\n// Or create without starting\nconst server = createServer(definition);\nserver.listen(4000);\n```\n\n## Zero Dependencies\n\nThis package has **zero npm dependencies**. It uses only Node.js built-ins (`http`, `fs`, `path`, `url`). Your `node_modules` stays clean.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsulthonzh%2Flocal-mock-api-factory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsulthonzh%2Flocal-mock-api-factory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsulthonzh%2Flocal-mock-api-factory/lists"}