{"id":14956033,"url":"https://github.com/igorkasyanchuk/fake_api","last_synced_at":"2025-04-09T12:09:08.081Z","repository":{"id":41107614,"uuid":"234056845","full_name":"igorkasyanchuk/fake_api","owner":"igorkasyanchuk","description":"The fastest way to prototype API in your Rails application","archived":false,"fork":false,"pushed_at":"2023-02-28T13:16:32.000Z","size":4915,"stargazers_count":142,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T11:03:24.726Z","etag":null,"topics":["api","rails","rails-api","rails-json-api","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://www.railsjazz.com/","language":"Ruby","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/igorkasyanchuk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":".github/FUNDING.yml","license":"MIT-LICENSE","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},"funding":{"patreon":"igorkasyanchuk"}},"created_at":"2020-01-15T10:34:22.000Z","updated_at":"2025-02-06T07:37:21.000Z","dependencies_parsed_at":"2024-04-12T12:30:05.966Z","dependency_job_id":"31ca4eaa-df26-4bd4-af6d-a3326a0546d5","html_url":"https://github.com/igorkasyanchuk/fake_api","commit_stats":{"total_commits":40,"total_committers":1,"mean_commits":40.0,"dds":0.0,"last_synced_commit":"0cd415e18b030f57ab7e6990a2f3a888cea815d9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Ffake_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Ffake_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Ffake_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkasyanchuk%2Ffake_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorkasyanchuk","download_url":"https://codeload.github.com/igorkasyanchuk/fake_api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694879,"owners_count":20980733,"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","rails","rails-api","rails-json-api","ruby","ruby-on-rails"],"created_at":"2024-09-24T13:12:12.701Z","updated_at":"2025-04-09T12:09:08.045Z","avatar_url":"https://github.com/igorkasyanchuk.png","language":"Ruby","funding_links":["https://patreon.com/igorkasyanchuk","https://www.patreon.com/igorkasyanchuk"],"categories":[],"sub_categories":[],"readme":"# Fake API\n\n[![Build Status](https://travis-ci.org/igorkasyanchuk/fake_api.svg?branch=master)](https://travis-ci.org/igorkasyanchuk/fake_api)\n[![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)\n[![https://www.patreon.com/igorkasyanchuk](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/patron.svg?raw=true)](https://www.patreon.com/igorkasyanchuk)\n[![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/r/igorkasyanchuk/fake_api)\n\nThe **fastest** way to prototype API with most real dummy data, and provide them to other team members.\n\nInstead of creating many new controllers and actions, and sending random data like `\"First name #{rand(100)}\"` you'll get real data for developing/testing.\n\nGem has a syntax similar to rails routes, factory bot, and uses faker to generate dummy data.\n\n![Demo](/docs/fake_api_demo.gif)\n\nFeatures:\n\n* fast API prototyping\n* clear and familiar syntax\n* Faker for test data generation\n  * including links to images if needed\n* manage cookies, session, headers with fake response\n* executes your factories in real-time, so you always get fresh and random data\n* has generator\n* has standalone mode (see documentation for more details)\n\n## Installation \u0026 Usage\n\nInstallation process is very simple.\n\n- add `gem 'fake_api'` to the Gemfile\n- run `bundle install`\n- mount gem in routes.rb `mount FakeApi::Engine =\u003e '/api'`\n- `rails g fake_api Product`. It will generate factory and routing files.\n- edit `app/fake_api/*.rb`, define your routing and factories.\n- open `localhost:300/api/projects.json` (see step 5) or `localhost:300/api/projects.xml` (to return XML in API response)\n- profit :)\n\nYou can keep your routing and factories in many files.\n\n## Examples\n\nSample of the factory:\n\n```ruby\n# app/fake_api/factory.rb\nclass Factory \u003c FakeApi::Factoring\n\n  # Example of User object\n  # you can see that it will generate link to fake image\n  factory(:user) do\n    {\n      id: rand(100),\n      first_name: Faker::Name.first_name,\n      last_name: Faker::Name.first_name,\n      avatar_url: Faker::Avatar.image(size: '128x128'),\n      age: rand(100)\n    }\n  end\n\n  # heare you can put \"relations\" to other factories\n  # see \"author\" node\n  factory(:project) do\n    {\n      id: rand(1_000),\n      title: Faker::Company.name,\n      description: Faker::Company.catch_phrase,\n      type: Faker::Company.type,\n      author: object(:user)\n    }\n  end\n\n  # or have factory which contains from the list of Projects and a single user\n  factory(:complex) do\n    {\n      projects: create_list(:project, 2),\n      user: object(:user)\n    }\n  end\n\nend\n```\n\nAnd sample of routing:\n\n```ruby\n# app/fake_api/app_routing.rb\nclass AppRouting \u003c FakeApi::Routing\n  get('/projects').and_return           { create_list(:project, 5) }.with_status(202).with_headers({TOKEN: \"SECRET\"})\n  get(%r{/projects/\\d+$}).and_return    { object(:project) }\n  post('/projects').and_return          { object(:project).merge({created: 'ok'}) }\n  delete(%r{/projects/\\d+$}).and_return { { result: :deleted } }.with_status(333)\n\n  post('/auth')\n    .and_return { { status: \"OK\" } }\n    .with_cookies({x: \"A\"})\n    .with_session({y: \"B\"})\n    .with_headers({token: \"C\"})\nend\n```\n\n## Factory Methods\n\n- `create_list(:factory_name, 10)` to create an array of 10 factories.\n- `object(:factory_nane)` to return a factory\n\n## Routing Methods\n\n- `get/post/put/patch/delete` to define route\n- `and_return` to specify the response. This response will be converted to FORMAT (json, xml, js, csv(for arrays) etc)\n- `with_cookies` to list returned cookies\n- `with_session` to list changes in session\n- `with_headers` to list returned headers\n\n## Standalone mode\n\nDeveloping standalone version of the gem:\n\n```bash\ncd test\nrackup -p 3000 -o 0.0.0.0\n```\n\nEdit `config.ru` to change example code.\n\n## Standalone mode\n\nThis is an example how you can start just fake_api server and define your factories and responses just inside one single file.\n\nPlease check example below and instructions how to start fakea_api in standalone mode.\n\nSince this is a rack app it could be just deployed to the server.\n\n```ruby\n# start it:\n# rackup -p 3000 -o 0.0.0.0\n\n# create file\n# config.ru\n\nrequire 'rubygems'\nrequire 'fake_api/standalone'\n\nfactory(:user) do\n  {\n    id: rand(100),\n    first_name: Faker::Name.first_name,\n    last_name: Faker::Name.last_name,\n    age: rand(100)\n  }\nend\n\nget('/users').and_return do\n  create_list(:user, 5)\nend\n\nget(%r{/users/\\d+$}).and_return do\n  object(:user)\nend\n\nrun FakeApi::Standalone.app on: '/api'\n```\n\nTheare is only one thing which is not convinient is a need to restart server after code changes.\n\n## TODO\n\n- render ERB?\n- exclude from code converage generator and dummy app\n- make code coverage 100%\n- access controller in the gem?\n- reload code in standalone app after code changes in dev mode\n\n## Contributing\n\nYou are welcome to contribute.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n[\u003cimg src=\"https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true\"\n/\u003e](https://www.railsjazz.com/?utm_source=github\u0026utm_medium=bottom\u0026utm_campaign=fake_api)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkasyanchuk%2Ffake_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorkasyanchuk%2Ffake_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkasyanchuk%2Ffake_api/lists"}