{"id":16184627,"url":"https://github.com/rmariuzzo/fotch","last_synced_at":"2025-03-19T02:31:19.683Z","repository":{"id":34162931,"uuid":"169912060","full_name":"rmariuzzo/fotch","owner":"rmariuzzo","description":"Fotch – In browser fake REST API for creative development purposes!","archived":false,"fork":false,"pushed_at":"2023-01-06T01:39:08.000Z","size":736,"stargazers_count":4,"open_issues_count":12,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T07:10:35.428Z","etag":null,"topics":["devtools","fake","fetch-api"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/rmariuzzo.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":"2019-02-09T20:48:09.000Z","updated_at":"2023-09-04T13:09:50.000Z","dependencies_parsed_at":"2023-01-15T05:00:55.572Z","dependency_job_id":null,"html_url":"https://github.com/rmariuzzo/fotch","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffotch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffotch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffotch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffotch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmariuzzo","download_url":"https://codeload.github.com/rmariuzzo/fotch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221720422,"owners_count":16869483,"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":["devtools","fake","fetch-api"],"created_at":"2024-10-10T07:10:52.044Z","updated_at":"2024-10-27T19:09:06.269Z","avatar_url":"https://github.com/rmariuzzo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Fotch – In browser fake REST API for creative development purposes!\n](.github/assets/banner.svg)](#installation)\n\n## Motivation\n\nWhen I code for fun, I occasionally need a backend REST API to play with. Usually, I feel too lazy to create a dumb REST API. I have dream about a simple library that I could plug in the frontend with little effort and simulate and persist data somewhere. Then **`fotch`** was born.\n\n## How it works?\n\n**`fotch`** monkey patches the `window.fetch` API and intercept all calls. When a matching call looks like a REST operation then **`fotch`** responds as you would expect from a REST API. All data is stored in `window.localStorage`.\n\n# Installation\n\n```bash\nnpm i fotch\n```\n\n# Usage\n\n```ts\nimport fotch from 'fotch'\n\nfotch.start()\n```\n\nThat's it! Seriously, just start using the `fetch` API as if there's a REST API. You can stop intercepting calls using `fotch.stop()`.\n\n| **[▶︎ View demo on CodeSandbox](https://codesandbox.io/s/rwqo347pjo?autoresize=1\u0026hidenavigation=1\u0026view=preview)** |\n| ----------------------------------------------------------------------------------------------------------------- |\n\n\n## Examples\n\n```js\n// Get a list of apples.\nfetch('/apples')\n\n// Get an apple by id.\nfetch('/apples/1')\n\n// Create an apple.\nfetch('/apples', { method: 'post', data: JSON.stringify({ color: 'red' }) })\n\n// Update an apple.\nfetch('/apples/1', { method: 'put', data: JSON.stringify({ color: 'green' }) })\n\n// Remove an apple.\nfetch('/apples/1', { method: 'delete' })\n```\n\n# Documentation\n\nThe first parameter can be a `string` or a [configuration object](#configuration-object).\n\nWhen the first parameter is a string it will be interpreted as match pattern.\n\n```js\nfotch.start('/api/')\n```\n\nThis will filter any `fetch` calls where the URL contains `/api/`.\n\n## Configuration object\n\nWhen the first parameter is a configuration object the following options can be used:\n\n| Name                              | Type           | Description                                                                                                                   |\n| --------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------- |\n| `match`                           | `string`       | The portion to match in a URL to filter `fetch` calls.                                                                        |\n| `delay`                           | `number`       | Specify a delay to all calls in milliseconds .                                                                                |\n| \u003c!-- Intentionally left blank --\u003e | `{ min, max }` | Specify a minimum and a maximum delay to all calls in milliseconds. **`fotch`** will return a random delay within that range. |\n\nIf you need more options then **[request it creating an issue](/issues/new)**.\n\n# Development\n\n1.  Clone this repository.\n2.  Install dependencies: `npm i`.\n3.  Make changes and create a PR.\n\n## Tests\n\n```sh\nnpm run test\n```\n\n## Releases\n\nReleases are triggered by `npm version` and handled by [GitHub Actions](https://github.com/rmariuzzo/fotch/actions?query=workflow%3Apublish).\n\n---\n\nMade with ♥ by [@rmariuzzo](https://github.com/rmariuzzo) and [contributors](https://github.com/rmariuzzo/fotch/graphs/contributors).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Ffotch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmariuzzo%2Ffotch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Ffotch/lists"}