{"id":13878644,"url":"https://github.com/gregschmit/rails-rest-framework","last_synced_at":"2025-05-10T17:33:46.795Z","repository":{"id":41257550,"uuid":"295910029","full_name":"gregschmit/rails-rest-framework","owner":"gregschmit","description":"A framework for DRY RESTful APIs in Ruby on Rails.","archived":false,"fork":false,"pushed_at":"2025-05-09T04:52:22.000Z","size":1926,"stargazers_count":50,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-10T17:23:12.566Z","etag":null,"topics":["api","rails","rest","restful-api"],"latest_commit_sha":null,"homepage":"https://rails-rest-framework.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/gregschmit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["gregschmit"],"custom":["https://www.paypal.me/schmitgreg"]}},"created_at":"2020-09-16T03:11:24.000Z","updated_at":"2025-05-10T15:34:33.000Z","dependencies_parsed_at":"2024-01-13T20:37:04.751Z","dependency_job_id":"36aaf39b-bb24-445f-b5a6-91fe8ca6cc69","html_url":"https://github.com/gregschmit/rails-rest-framework","commit_stats":{"total_commits":365,"total_committers":3,"mean_commits":"121.66666666666667","dds":0.03013698630136985,"last_synced_commit":"7be41c1b2d2dc23a3688aa247739c657b9e62fc9"},"previous_names":[],"tags_count":111,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Frails-rest-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Frails-rest-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Frails-rest-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregschmit%2Frails-rest-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregschmit","download_url":"https://codeload.github.com/gregschmit/rails-rest-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253453989,"owners_count":21911206,"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","rest","restful-api"],"created_at":"2024-08-06T08:01:55.559Z","updated_at":"2025-05-10T17:33:46.787Z","avatar_url":"https://github.com/gregschmit.png","language":"Ruby","readme":"# Rails REST Framework\n\n[![Gem Version](https://badge.fury.io/rb/rest_framework.svg)](https://badge.fury.io/rb/rest_framework)\n[![Pipeline](https://github.com/gregschmit/rails-rest-framework/actions/workflows/pipeline.yml/badge.svg)](https://github.com/gregschmit/rails-rest-framework/actions/workflows/pipeline.yml)\n[![Coverage](https://coveralls.io/repos/github/gregschmit/rails-rest-framework/badge.svg?branch=master)](https://coveralls.io/github/gregschmit/rails-rest-framework?branch=master)\n[![Maintainability](https://api.codeclimate.com/v1/badges/ba5df7706cb544d78555/maintainability)](https://codeclimate.com/github/gregschmit/rails-rest-framework/maintainability)\n\nA framework for DRY RESTful APIs in Ruby on Rails.\n\n**The Problem**: Building controllers for APIs usually involves writing a lot of redundant CRUD\nlogic, and routing them can be obnoxious. Building and maintaining features like ordering,\nfiltering, and pagination can be tedious.\n\n**The Solution**: This framework implements browsable API responses, CRUD actions for your models,\nand features like ordering/filtering/pagination, so you can focus on your application logic.\n\nWebsite/Guide: [rails-rest-framework.com](https://rails-rest-framework.com)\n\nDemo API: [rails-rest-framework.com/api/demo](https://rails-rest-framework.com/api/demo)\n\nSource: [github.com/gregschmit/rails-rest-framework](https://github.com/gregschmit/rails-rest-framework)\n\nYARD Docs: [rubydoc.info/gems/rest_framework](https://rubydoc.info/gems/rest_framework)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"rest_framework\"\n```\n\nAnd then run:\n\n```shell\nbundle install\n```\n\n## Quick Usage Tutorial\n\nThis section provides some simple examples to quickly get you started using the framework.\n\nFor the purpose of this example, you'll want to add an `api_controller.rb` to your controllers, as\nwell as a directory for the resources:\n\n```text\ncontrollers/\n├─ api_controller.rb\n└─ api/\n   ├─ root_controller.rb\n   ├─ movies_controller.rb\n   └─ users_controller.rb\n```\n\n### Controller Mixins\n\nThe root `ApiController` can include any common behavior you want to share across all your API\ncontrollers:\n\n```ruby\nclass ApiController \u003c ApplicationController\n  include RESTFramework::BaseControllerMixin\n\n  # Setting up a paginator class here makes more sense than defining it on every child controller.\n  self.paginator_class = RESTFramework::PageNumberPaginator\n  self.page_size = 30\nend\n```\n\nA root controller can provide actions that exist on the root of your API. It's best to define a\ndedicated root controller, rather than using the `ApiController` for this purpose, so that actions\ndon't propagate to child controllers:\n\n```ruby\nclass Api::RootController \u003c ApiController\n  self.extra_actions = {test: :get}\n\n  def root\n    render(\n      api: {\n        message: \"Welcome to the API.\",\n        how_to_authenticate: \u003c\u003c~END.lines.map(\u0026:strip).join(\" \"),\n          You can use this API with your normal login session. Otherwise, you can insert your API\n          key into a Bearer Authorization header, or into the URL parameters with the name\n          `api_key`.\n        END\n      },\n    )\n  end\n\n  def test\n    render(api: {message: \"Hello, world!\"})\n  end\nend\n```\n\nAnd here is an example of a resource controller:\n\n```ruby\nclass Api::MoviesController \u003c ApiController\n  include RESTFramework::ModelControllerMixin\n\n  self.fields = [:id, :name, :release_date, :enabled]\n  self.extra_member_actions = {first: :get}\n\n  def first\n    # Always use the bang method, since the framework will rescue `RecordNotFound` and return a\n    # sensible error response.\n    render(api: self.get_records.first!)\n  end\n\n  def get_recordset\n    return Movie.where(enabled: true)\n  end\nend\n```\n\nWhen `fields` is nil, then it will default to all columns. The `fields` attribute can also be a hash\nto include or exclude fields rather than defining them manually:\n\n```ruby\nclass Api::UsersController \u003c ApiController\n  include RESTFramework::ModelControllerMixin\n\n  self.fields = {include: [:calculated_popularity], exclude: [:impersonation_token]}\nend\n```\n\n### Routing\n\nUse `rest_route` for non-resourceful controllers, or `rest_resource` / `rest_resources` resourceful\nrouters. These routers add some features to the Rails builtin `resource`/`resources` routers, such\nas automatically routing extra actions defined on the controller. To route the root, use\n`rest_root`.\n\n```ruby\nRails.application.routes.draw do\n  # If you wanted to route actions from the `ApiController`, then you would use this:\n  # rest_root :api  # Will find `api_controller` and route the `root` action to '/api'.\n\n  namespace :api do\n    rest_root  # Will route `Api::RootController#root` to '/' in this namespace ('/api').\n    rest_resources :movies\n    rest_resources :users\n  end\nend\n```\n\n## Development/Testing\n\nAfter you clone the repository, cd'ing into the directory should create a new gemset if you are\nusing RVM. Then run `bin/setup` to install the appropriate gems and set things up.\n\nThe top-level `bin/rails` proxies all Rails commands to the test project, so you can operate it via\nthe usual commands (e.g., `rails test`, `rails console`). For development, use `bin/dev` to run the\nweb server and the job queue, which serves the test app and coverage/brakeman reports:\n\n- Test App: [http://127.0.0.1:3000](http://127.0.0.1:3000)\n- API: [http://127.0.0.1:3000/api](http://127.0.0.1:3000/api)\n- Reports: [http://127.0.0.1:3000/reports](http://127.0.0.1:3000/reports)\n","funding_links":["https://github.com/sponsors/gregschmit","https://www.paypal.me/schmitgreg"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregschmit%2Frails-rest-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregschmit%2Frails-rest-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregschmit%2Frails-rest-framework/lists"}