{"id":15379252,"url":"https://github.com/ducksoupdev/mock-api-local-server","last_synced_at":"2026-04-19T00:35:28.140Z","repository":{"id":214747198,"uuid":"737277560","full_name":"ducksoupdev/mock-api-local-server","owner":"ducksoupdev","description":"A mock API server for local development. It serves and maps JSON files to URLs. It also handles http writes (POST, PUT, PATCH, DELETE).","archived":false,"fork":false,"pushed_at":"2024-01-03T09:23:52.000Z","size":66,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-12T01:08:48.484Z","etag":null,"topics":[],"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/ducksoupdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2023-12-30T12:57:17.000Z","updated_at":"2025-04-11T07:53:17.000Z","dependencies_parsed_at":"2023-12-30T13:25:18.167Z","dependency_job_id":"a3504b11-32ce-4f2b-a71c-d8fde753a64e","html_url":"https://github.com/ducksoupdev/mock-api-local-server","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"e30336301cefa8564a96a2785b9b9565878cbd4f"},"previous_names":["ducksoupdev/mock-api-local-server","ducksoupdev/mock-api-server"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ducksoupdev/mock-api-local-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducksoupdev%2Fmock-api-local-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducksoupdev%2Fmock-api-local-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducksoupdev%2Fmock-api-local-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducksoupdev%2Fmock-api-local-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ducksoupdev","download_url":"https://codeload.github.com/ducksoupdev/mock-api-local-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducksoupdev%2Fmock-api-local-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31989934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"ssl_error","status_checked_at":"2026-04-18T20:23:29.375Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-10-01T14:18:38.498Z","updated_at":"2026-04-19T00:35:28.115Z","avatar_url":"https://github.com/ducksoupdev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mock API local server\n\nThis is a mock API server for local development. It serves and maps JSON files to URLs. It also handles http writes (POST, PUT, PATCH, DELETE).\n\n## Contents\n\n- [Installation](#installation)\n- [Getting started](#getting-started)\n  - [Routes](#routes)\n  - [The `index.json` file](#the-indexjson-file)\n  - [Query string responses](#query-string-responses)\n  - [Error responses](#error-responses)\n- [Resources](#resources)\n  - [Custom responses](#custom-responses)\n  - [Resource creation](#resource-creation)\n- [Running the server](#running-the-server)\n  - [Linux](#linux)\n  - [macOS](#macos)\n  - [CLI flags](#cli-flags)\n- [Development](#development)\n\n## Installation\n\nRun the following to install:\n\n```bash\n# install globally\nnpm i -g mock-api-local-server\n\n# install local to your project\nnpm i mock-api-local-server\n```\n\n## Getting started\n\nTo use the server, create an NPM script in your `package.json` file:\n\n```json\n{\n  \"scripts\": {\n    \"start\": \"mock-api-local-server\"\n  }\n}\n```\n\nThe server will listen on port 8080 and will serve the contents of the `public` directory by default.\nThe `public` directory contains a structure that defines the routes and the responses based on files and directories.\n\n### Routes\n\nThe routes are defined in the `public` directory. The directory structure defines the routes and maps to URLs. For example, the following directory structure:\n\n```\npublic/\n  users/\n    1/\n      index.json\n    2/\n      index.json\n    index.json\n```\n\nDefines the following routes:\n\n```\nGET /users\nGET /users/1\nGET /users/2\n```\n\n### The `index.json` file\n\nAn `index.json` file can be created in one of the directories. If present, this file is served if the directory is requested without specifying the file name.\n\n### Query string responses\n\nFor `GET` requests where a specific response based on query string is required, a response file can be created that sets the response.\n\nAs an example, a response for URL `/api/test3?param1=value1\u0026param2=value2`, create either `/api/test3_param1=value1\u0026param2=value2.json` or `/api/test3_param1=value1\u0026param2=value2/index.json` with appropriate content for the response.\n\n### Error responses\n\nFor `GET` requests where a specific response is required, an error response file can be created that sets the response.\nError responses can be HTML or JSON. **Only a single file can exist in the directory**.\n\nAs an example, to force a 404 response for URL `/api/not-found`, create either `/api/not-found/404.json` or `/api/not-found/404.html` with appropriate content for the response.\n\nFor `POST`, `PUT`, `PATCH` and `DELETE` requests, an error response file can be created that sets the response.\nError responses must be JSON. **Only a single file can exist in the directory**.\n\nAs an example, to force a 404 response for URL `/api/not-found`, create a `/api/not-found/POST_404.json` file with appropriate content for the response.\n\n## Resources\n\nThe mock server provides automatic `POST`, `PUT`, `PATCH` and `DELETE` methods for any URL path. This allows local mocking of API endpoints.\n\nThe following statuses are returned from these methods.\n\n| Method   | Status |\n|----------|--------|\n| `POST`   | 201    |\n| `PUT`    | 204    |\n| `PATCH`  | 204    |\n| `DELETE` | 204    |\n\n### Custom responses\n\nCustom responses can be provided by creating a file with the method name in the directory.\n\nFor example, to provide a custom response for `POST` requests to `/api/test`, create `/api/test/POST.json` with appropriate content for the response.\n\n### Resource creation\n\nResource creation can be enabled using the `--create` flag. This will allow the server to create resources when a `POST`, `PUT` or `PATCH` request is made.\n\nFor example, the file `/api/test/POST.json` is created for a `POST` request to `/api/test` containing the body of the request.\n\nQuery string parameters are also supported. For example, the file `/api/test/POST_param1=value1\u0026param2=value2.json` is created for a `POST` request to `/api/test?param1=value1\u0026param2=value2` containing the body of the request.\n\n### CLI flags\n\nThe following CLI flags are available:\n\n| Option          | Description                        | Default  |\n|-----------------|------------------------------------|----------|\n| `--port`        | Set the port to use.               | `8080`   |\n| `--static-dirs` | Set the directories to serve from. | `public` |\n| `--extensions`  | Set the default file extensions.   | `json`   |\n| `--create`      | Enable resource creation.          | `false`  |\n| `--use-https`   | Enable HTTPS.                      | `false`  |\n\n```json\n{\n  \"scripts\": {\n    \"start\": \"mock-api-local-server --port 1234 --static-dirs static --create --use-https\"\n  }\n}\n```\n\n## Development\n\nThe server is written in Node.js. To run the server locally, run the following commands:\n\n```bash\n# install dependencies\nnpm install\n\n# start the server\nnpm start\n\n# start the server with resource creation enabled\nnpm run start:create\n\n# start the server using https\nnpm run start:https\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [`LICENSE`](LICENSE) file for details.\n\n## Contributing\n\nAny kind of positive contribution is welcome! Please help us to grow by contributing to the project.\n\nIf you wish to contribute, you can work on any features you think would enhance the library. After adding your code, please send us a Pull Request.\n\n\u003e Please read [CONTRIBUTING](CONTRIBUTING.md) for details on our [CODE OF CONDUCT](CODE_OF_CONDUCT.md), and the process for submitting pull requests to us.\n\n## Support\n\nWe all need support and motivation. Please give this project a ⭐️ to encourage and show that you liked it. Don't forget to leave a star ⭐️ before you move away.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducksoupdev%2Fmock-api-local-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fducksoupdev%2Fmock-api-local-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducksoupdev%2Fmock-api-local-server/lists"}