{"id":13453811,"url":"https://github.com/micromata/http-fake-backend","last_synced_at":"2025-03-24T01:31:57.757Z","repository":{"id":5453133,"uuid":"53200211","full_name":"micromata/http-fake-backend","owner":"micromata","description":"Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.","archived":true,"fork":false,"pushed_at":"2023-10-20T18:05:56.000Z","size":581,"stargazers_count":311,"open_issues_count":4,"forks_count":21,"subscribers_count":23,"default_branch":"main","last_synced_at":"2024-10-28T20:39:46.529Z","etag":null,"topics":["api","backend","data","fake","fake-data","http","http-server","json","json-files","mock","mocking","mocking-server","mocks","node","nodejs","rest","rest-api","restful","restful-api"],"latest_commit_sha":null,"homepage":"","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/micromata.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-03-05T12:25:43.000Z","updated_at":"2024-06-16T13:43:27.000Z","dependencies_parsed_at":"2024-01-02T20:54:14.406Z","dependency_job_id":null,"html_url":"https://github.com/micromata/http-fake-backend","commit_stats":{"total_commits":109,"total_committers":3,"mean_commits":"36.333333333333336","dds":0.04587155963302747,"last_synced_commit":"6f77e92e0ec6b8019a1118202d5eef097af1ac5a"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micromata%2Fhttp-fake-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micromata%2Fhttp-fake-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micromata%2Fhttp-fake-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micromata%2Fhttp-fake-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micromata","download_url":"https://codeload.github.com/micromata/http-fake-backend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245194311,"owners_count":20575739,"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":["api","backend","data","fake","fake-data","http","http-server","json","json-files","mock","mocking","mocking-server","mocks","node","nodejs","rest","rest-api","restful","restful-api"],"created_at":"2024-07-31T08:00:47.856Z","updated_at":"2025-03-24T01:31:54.950Z","avatar_url":"https://github.com/micromata.png","language":"JavaScript","funding_links":[],"categories":["Packages","Repository","包","目录","HTTP"],"sub_categories":["HTTP"],"readme":"[![GitHub version](https://badge.fury.io/gh/micromata%2Fhttp-fake-backend.svg)](https://badge.fury.io/gh/micromata%2Fhttp-fake-backend)\n[![Build Status](https://travis-ci.org/micromata/http-fake-backend.svg?branch=master)](https://travis-ci.org/micromata/http-fake-backend)\n[![Coverage Status](https://coveralls.io/repos/github/micromata/http-fake-backend/badge.svg?branch=master)](https://coveralls.io/github/micromata/http-fake-backend?branch=master)\n[![Dependency Status](https://david-dm.org/micromata/http-fake-backend.svg)](https://david-dm.org/micromata/http-fake-backend)\n[![devDependency Status](https://david-dm.org/micromata/http-fake-backend/dev-status.svg?theme=shields.io)](https://david-dm.org/micromata/http-fake-backend#info=devDependencies)\n[![Unicorn](https://img.shields.io/badge/unicorn-approved-ff69b4.svg?style=flat)](https://www.youtube.com/watch?v=qRC4Vk6kisY) \n\n# http-fake-backend\n\n\u003e Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.\n\n*It actually can serve the content of other file types as well as sending the files itself as response.*\n\nComes as a Node.js server. Useful for mocking, testing and developing independent of the »real« backend.\n\n## Sorry, this project is unmaintained 😢\nThanks to all contributors for your work!\n\nWe’ve just pushed a last release which fixes some bugs, make this thing run with Node 18.\n\n## Example\nLet’s say you need an endpoint like \u003chttp://localhost:8081/api/example\u003e which should return:\n\n```\n{\n  \"response\": \"Yeah\"\n}\n```\n\nIt’s a matter of seconds to create this endpoint with help of this little hapi server.\n\nIt might take a few seconds longer as setting up the well-made [JSON Server](https://github.com/typicode/json-server) but it’s way more flexible.\n\n## Requirements\n\n- Node.js (18.12.0 or greater)\n\n## Install\n\n```bash\ngit clone https://github.com/micromata/http-fake-backend.git\nnpm install\n```\n\nOr with help of [Yeoman](http://yeoman.io)\n\n```bash\nnpm install -g yo\nnpm install -g generator-http-fake-backend\n```\n\nThis comes in handy, because the Yeoman generator has a sub-generator to setup endpoints of your fake backend very convenient. See \u003chttps://github.com/micromata/generator-http-fake-backend\u003e.\n\n## Default Address\nThe server runs at \u003chttp://localhost:8081/\u003e providing a page with links to all existing API endpoints.\n\n## Start the server\n\nThere are the following two options.\n\n### During development\n\n```\nnpm run start:dev\n```\n\nThis way the server uses `nodemon` to restart itself on changes. \n\n\n### Later (eg. for tests in CI)\n\n```\nnpm start\n```\n\nJust starts the server via node.\n\n## Configure endpoints\n\nEach endpoint needs a configuration file in `/server/api/` to define routes, http method and the response.\n\n### Example configurations\n\n#### Simple Example\n\n`/server/api/simpleExample.js`:\n\n```js\nmodule.exports = SetupEndpoint({\n    name: 'simpleExample',\n    urls: [{\n        requests: [\n            { response: '/response-files/simpleExample.json' }\n        ]\n    }]\n});\n```\n\n#### Advanced Example\n\n`/server/api/anotherExample.js`:\n\n```js\nmodule.exports = SetupEndpoint({\n    name: 'anotherExample',\n    urls: [{\n        params: '/read',\n        requests: [{\n            method: 'GET',\n            response: '/response-files/anotherExample.json'\n        }]\n    }, {\n        params: '/update/{id}',\n        requests: [{\n            method: ['PUT', 'PATCH'],\n            response: {\n                success: true\n            }\n        }, {\n            method: 'DELETE',\n            response: {\n                deleted: true\n            }\n        }]\n    }, ]\n});\n```\n\n#### Serving different content types\n\n`/server/api/fileTypes.js`:\n\n```js\nmodule.exports = SetupEndpoint({\n    name: 'fileTypes',\n    urls: [{\n        params: '/json',\n        requests: [{\n            response: '/response-files/simpleExample.json'\n        }]\n    }, {\n        params: '/text',\n        requests: [{\n            response: '/response-files/example.txt',\n            mimeType: 'text/plain'\n        }]\n    }, {\n        params: '/html',\n        requests: [{\n            response: '/response-files/example.html',\n            mimeType: 'text/html'\n        }]\n    }, {\n        params: '/pdf',\n        requests: [{\n            response: '/response-files/example.pdf',\n            sendFile: true\n        }]\n    }]\n});\n```\n\n#### Faking HTTP errors and status code\n\n`/server/api/fakingStatusCodes.js`:\n\n```js\nmodule.exports = SetupEndpoint({\n    name: 'statusCodes',\n    urls: [\n        {\n            params: '/boomError',\n            requests: [{\n                // Returns a 402 status code + error message provided by boom:\n                // {\n                //   \"error\" : \"Payment Required\",\n                //   \"message\" : \"Payment Required\",\n                //   \"statusCode\" : 402\n                // }\n                statusCode: 402\n            }]\n        },\n        {\n            params: '/customError',\n            requests: [{\n                // Returns a HTTP status code 406 and a self defined response:\n                response: { error: true },\n                statusCode: 406\n            }]\n        },\n        {\n            params: '/regularResponse',\n            requests: [{\n                // Returns a 401 error provided by boom\n                // as defined on endpoint level\n                response: '/response-files/anotherExample.json'\n            }]\n        }\n    ],\n    statusCode: 401\n});\n```\n\nThe configuration object in Detail:\n\n* `name`  \n  * Is used to set the endpoint.\n* `urls`\n  * You need to add at least one url object.\n* `urls.params`\n  * Optional\n  * URL path parameters with fixed and/or variable path segments.\n  * Example:\n    * `params: '/update/{id}'`\n  * See hapi docs. For example regarding optional [path parameters](http://hapijs.com/api#path-parameters).\n* `urls.requests`\n    *  You need to add at least one request object.\n    *  Multiple request objects are needed in case you like to serve different responses via different HTTP methods with the same URL.\n* `urls.requests.method` \n    * optional. Uses `GET` when not defined.\n    * `string`, or `array` of strings.\n    * is used to define the http method(s) to which the endpoint will listen.\n* `urls.requests.response` \n  * Could be a string pointing to a file:\n    *   `response: '/response-files/articles.json'`\n  * Or just a JavaScript object:\n    * `response: { success: true }`\n* `urls.requests.mimeType` \n  * Optional (string). Defaults to `application/json`.\n  * Is used to set the `content-type` response header. \n* `urls.requests.sendFile`\n  * Optional (boolean). Defaults to `false`.\n  * Sends the file as response instead of returning the file content.\n* `urls.requests.statusCode` \n  * Optional (boolean). Defaults to `200`\n  * The HTTP status code of the response.\n  * Will return: \n    * a status code with a self defined response if you provide a response property\n    * a status code with a predefined error object provided by [boom](https://github.com/hapijs/boom) if you dont provide a response property for that request.\n* `statusCode`\n  * Optional\n  * Every subroute of this endpoint will return a HTTP error with the given status code provided by [boom](https://github.com/hapijs/boom).\n\n## Configure server\n\nThe main config is handled via a file named `.env` with the following content:\n\n```dosini\n# NODE_ENV\n# Could be either `development` or `production`\nNODE_ENV=development\n\n# Port of the Server\nSERVER_PORT=8081\n\n# Port for running the tests\nTEST_PORT=9090\n\n# URL Prefix for the endpoints\n# eg. http://localhost:8081/api/foo\nAPI_PREFIX=/api\n\n# Custom response header\n#CUSTOM_HEADER_NAME=Authorization\n#CUSTOM_HEADER_VALUE=Bearer eyJhbGciOiJIUzUxMiJ9\n\n```\n\n\n## Related\n\n* [Yeoman Generator](https://github.com/micromata/generator-http-fake-backend) – Easily generate your fake backend and use sub-generators to setup endpoints  like :zap:\n\n## License\n\nPlease be aware of the licenses of the components we use in this project.\nEverything else that has been developed by the contributions to this project is under [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicromata%2Fhttp-fake-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicromata%2Fhttp-fake-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicromata%2Fhttp-fake-backend/lists"}